Added dkim key backup

This commit is contained in:
Spitap
2022-10-25 16:04:55 +02:00
parent e34eb4b337
commit 4c1f8710b5

View File

@@ -20,6 +20,8 @@ class Backup:
||--> custom ||--> custom
|--> { (copy of) /etc/amavis/conf.d/99-custom } |--> { (copy of) /etc/amavis/conf.d/99-custom }
|--> { (copy of) /etc/postfix/custom_whitelist.cidr } |--> { (copy of) /etc/postfix/custom_whitelist.cidr }
|--> { (copy of) dkim folder }
|--> {dkim.pem}...
||--> databases ||--> databases
|--> modoboa.sql |--> modoboa.sql
|--> { amavis.sql } |--> { amavis.sql }
@@ -63,16 +65,18 @@ class Backup:
if not self.silent_backup: if not self.silent_backup:
delete_dir = input( delete_dir = input(
"Warning : backup folder is not empty, it will be purged if you continue... [Y/n]\n").lower() "Warning : backup folder is not empty, it will be purged if you continue... [Y/n]\n").lower()
if self.silent_backup or (not self.silent_backup and (delete_dir == "y" or delete_dir == "yes")): if self.silent_backup or (not self.silent_backup and (delete_dir == "y" or delete_dir == "yes")):
try: try:
os.remove(os.path.join(path, "installer.cfg")) os.remove(os.path.join(path, "installer.cfg"))
except FileNotFoundError: except FileNotFoundError:
pass pass
shutil.rmtree(os.path.join(path, "custom"),ignore_errors=False) shutil.rmtree(os.path.join(path, "custom"),
ignore_errors=False)
shutil.rmtree(os.path.join(path, "mails"), ignore_errors=False) shutil.rmtree(os.path.join(path, "mails"), ignore_errors=False)
shutil.rmtree(os.path.join(path, "databases"), ignore_errors=False) shutil.rmtree(os.path.join(path, "databases"),
ignore_errors=False)
else: else:
utils.printcolor( utils.printcolor(
"Error, backup dir not clean.", utils.RED "Error, backup dir not clean.", utils.RED
@@ -139,6 +143,7 @@ class Backup:
def custom_config_backup(self): def custom_config_backup(self):
"""Custom config : """Custom config :
- DKIM keys: {{keys_storage_dir}}
- Amavis : /etc/amavis/conf.d/99-custom - Amavis : /etc/amavis/conf.d/99-custom
- Postwhite : /etc/postwhite.conf - Postwhite : /etc/postwhite.conf
Feel free to suggest to add others!""" Feel free to suggest to add others!"""
@@ -148,6 +153,15 @@ class Backup:
custom_path = os.path.join( custom_path = os.path.join(
self.backup_path, "custom") self.backup_path, "custom")
# DKIM Key
if (self.config.has_option("opendkim", "enabled") and
self.config.getboolean("opendkim", "enabled")):
dkim_keys = self.config.get(
"opendkim", "keys_storage_dir", fallback="/var/lib/dkim")
shutil.copytree(dkim_keys, os.path.join(custom_path, "dkim"))
utils.printcolor(
"DKIM keys saved!", utils.GREEN)
# AMAVIS # AMAVIS
if (self.config.has_option("amavis", "enabled") and if (self.config.has_option("amavis", "enabled") and
self.config.getboolean("amavis", "enabled")): self.config.getboolean("amavis", "enabled")):