Improved backups

This commit is contained in:
Spitap
2025-11-01 17:18:22 +01:00
parent 30b9393877
commit 3e5b9ab310
9 changed files with 287 additions and 459 deletions

View File

@@ -19,10 +19,7 @@ class Postwhite(base.Installer):
"crontab=/etc/cron.d/postwhite",
]
no_daemon = True
packages = {
"deb": ["bind9-host", "unzip"],
"rpm": ["bind-utils", "unzip"]
}
packages = {"deb": ["bind9-host", "unzip"], "rpm": ["bind-utils", "unzip"]}
def install_from_archive(self, repository, target_dir):
"""Install from an archive."""
@@ -36,8 +33,7 @@ class Postwhite(base.Installer):
if os.path.exists(archive_dir):
shutil.rmtree(archive_dir)
utils.exec_cmd("unzip master.zip", cwd=target_dir)
utils.exec_cmd(
"mv {name}-master {name}".format(name=app_name), cwd=target_dir)
utils.exec_cmd("mv {name}-master {name}".format(name=app_name), cwd=target_dir)
os.unlink(target)
return archive_dir
@@ -45,10 +41,8 @@ class Postwhite(base.Installer):
"""Additionnal tasks."""
install_dir = "/usr/local/bin"
self.install_from_archive(SPF_TOOLS_REPOSITORY, install_dir)
self.postw_dir = self.install_from_archive(
POSTWHITE_REPOSITORY, install_dir)
utils.copy_file(
os.path.join(self.postw_dir, "postwhite.conf"), self.config_dir)
self.postw_dir = self.install_from_archive(POSTWHITE_REPOSITORY, install_dir)
utils.copy_file(os.path.join(self.postw_dir, "postwhite.conf"), self.config_dir)
self.postw_bin = os.path.join(self.postw_dir, "postwhite")
utils.exec_cmd("{} /etc/postwhite.conf".format(self.postw_bin))
@@ -57,13 +51,13 @@ class Postwhite(base.Installer):
postswhite_custom = "/etc/postwhite.conf"
if os.path.isfile(postswhite_custom):
utils.copy_file(postswhite_custom, path)
utils.printcolor(
"Postwhite configuration saved!", utils.GREEN)
utils.printcolor("Postwhite configuration saved!", utils.GREEN)
def restore(self):
"""Restore config files."""
postwhite_backup_configuration = os.path.join(
self.archive_path, "custom/postwhite.conf")
self.archive_path, "custom/postwhite/postwhite.conf"
)
if os.path.isfile(postwhite_backup_configuration):
utils.copy_file(postwhite_backup_configuration, self.config_dir)
utils.success("postwhite.conf restored from backup")