Improved backups
This commit is contained in:
@@ -10,18 +10,29 @@ from . import backup, install
|
||||
|
||||
|
||||
class Amavis(base.Installer):
|
||||
|
||||
"""Amavis installer."""
|
||||
|
||||
appname = "amavis"
|
||||
packages = {
|
||||
"deb": [
|
||||
"libdbi-perl", "amavisd-new", "arc", "arj", "cabextract",
|
||||
"liblz4-tool", "lrzip", "lzop", "p7zip-full", "rpm2cpio",
|
||||
"libdbi-perl",
|
||||
"amavisd-new",
|
||||
"arc",
|
||||
"arj",
|
||||
"cabextract",
|
||||
"liblz4-tool",
|
||||
"lrzip",
|
||||
"lzop",
|
||||
"p7zip-full",
|
||||
"rpm2cpio",
|
||||
"unrar-free",
|
||||
],
|
||||
"rpm": [
|
||||
"amavisd-new", "arj", "lz4", "lzop", "p7zip",
|
||||
"amavisd-new",
|
||||
"arj",
|
||||
"lz4",
|
||||
"lzop",
|
||||
"p7zip",
|
||||
],
|
||||
}
|
||||
with_db = True
|
||||
@@ -43,8 +54,10 @@ class Amavis(base.Installer):
|
||||
"""Return appropriate config files."""
|
||||
if package.backend.FORMAT == "deb":
|
||||
return [
|
||||
"conf.d/05-node_id", "conf.d/15-content_filter_mode",
|
||||
"conf.d/50-user"]
|
||||
"conf.d/05-node_id",
|
||||
"conf.d/15-content_filter_mode",
|
||||
"conf.d/50-user",
|
||||
]
|
||||
return ["amavisd.conf"]
|
||||
|
||||
def get_packages(self):
|
||||
@@ -62,7 +75,7 @@ class Amavis(base.Installer):
|
||||
if major_version >= 13:
|
||||
packages = [p if p != "liblz4-tool" else "lz4" for p in packages]
|
||||
return packages
|
||||
|
||||
|
||||
if self.db_driver == "pgsql":
|
||||
db_driver = "Pg"
|
||||
elif self.db_driver == "mysql":
|
||||
@@ -71,9 +84,9 @@ class Amavis(base.Installer):
|
||||
raise NotImplementedError("DB driver not supported")
|
||||
packages += ["perl-DBD-{}".format(db_driver)]
|
||||
name, version = utils.dist_info()
|
||||
if version.startswith('7'):
|
||||
if version.startswith("7"):
|
||||
packages += ["cabextract", "lrzip", "unar", "unzoo"]
|
||||
elif version.startswith('8'):
|
||||
elif version.startswith("8"):
|
||||
packages += ["perl-IO-stringy"]
|
||||
return packages
|
||||
|
||||
@@ -85,12 +98,10 @@ class Amavis(base.Installer):
|
||||
version = package.backend.get_installed_version("amavis")
|
||||
if version is None:
|
||||
raise utils.FatalError("Amavis is not installed")
|
||||
path = self.get_file_path(
|
||||
"amavis_{}_{}.sql".format(self.dbengine, version))
|
||||
path = self.get_file_path("amavis_{}_{}.sql".format(self.dbengine, version))
|
||||
if not os.path.exists(path):
|
||||
version = ".".join(version.split(".")[:-1]) + ".X"
|
||||
path = self.get_file_path(
|
||||
"amavis_{}_{}.sql".format(self.dbengine, version))
|
||||
path = self.get_file_path("amavis_{}_{}.sql".format(self.dbengine, version))
|
||||
if not os.path.exists(path):
|
||||
raise utils.FatalError("Failed to find amavis database schema")
|
||||
return path
|
||||
@@ -107,20 +118,21 @@ class Amavis(base.Installer):
|
||||
|
||||
def custom_backup(self, path):
|
||||
"""Backup custom configuration if any."""
|
||||
if package.backend.FORMAT == "deb":
|
||||
amavis_custom = f"{self.config_dir}/conf.d/99-custom"
|
||||
if os.path.isfile(amavis_custom):
|
||||
utils.copy_file(amavis_custom, path)
|
||||
utils.success("Amavis custom configuration saved!")
|
||||
backup("spamassassin", self.config, os.path.dirname(path))
|
||||
amavis_custom = f"{self.config_dir}/conf.d/99-custom"
|
||||
if os.path.isfile(amavis_custom):
|
||||
utils.copy_file(amavis_custom, path)
|
||||
utils.success("Amavis custom configuration saved!")
|
||||
backup("spamassassin", self.config, self.base_backup_path)
|
||||
|
||||
def restore(self):
|
||||
"""Restore custom config files."""
|
||||
if package.backend.FORMAT != "deb":
|
||||
return
|
||||
amavis_custom_configuration = os.path.join(
|
||||
self.archive_path, "custom/99-custom")
|
||||
self.archive_path, "custom/amavis/99-custom"
|
||||
)
|
||||
if os.path.isfile(amavis_custom_configuration):
|
||||
utils.copy_file(amavis_custom_configuration, os.path.join(
|
||||
self.config_dir, "conf.d"))
|
||||
utils.copy_file(
|
||||
amavis_custom_configuration, os.path.join(self.config_dir, "conf.d")
|
||||
)
|
||||
utils.success("Custom amavis configuration restored.")
|
||||
|
||||
Reference in New Issue
Block a user