DKIM keys restore, Radicale backup/restore, fixes
This commit is contained in:
@@ -42,11 +42,12 @@ class Amavis(base.Installer):
|
||||
def get_config_files(self):
|
||||
"""Return appropriate config files."""
|
||||
if package.backend.FORMAT == "deb":
|
||||
if self.restore is not None:
|
||||
amavis_custom_configuration = os.path.join(
|
||||
self.restore, "custom/99-custom")
|
||||
if self.restore and os.path.isfile(amavis_custom_configuration):
|
||||
if os.path.isfile(amavis_custom_configuration):
|
||||
utils.copy_file(amavis_custom_configuration, os.path.join(
|
||||
self.config_dir, "/conf.d"))
|
||||
self.config_dir, "conf.d"))
|
||||
utils.printcolor(
|
||||
"Custom amavis configuration restored.", utils.GREEN)
|
||||
return [
|
||||
|
||||
@@ -22,6 +22,7 @@ class Backup:
|
||||
|--> { (copy of) /etc/postfix/custom_whitelist.cidr }
|
||||
|--> { (copy of) dkim folder }
|
||||
|--> {dkim.pem}...
|
||||
|--> { (copy of) radicale home_dir }
|
||||
||--> databases
|
||||
|--> modoboa.sql
|
||||
|--> { amavis.sql }
|
||||
@@ -144,6 +145,7 @@ class Backup:
|
||||
def custom_config_backup(self):
|
||||
"""Custom config :
|
||||
- DKIM keys: {{keys_storage_dir}}
|
||||
- Radicale collection (calendat, contacts): {{home_dir}}
|
||||
- Amavis : /etc/amavis/conf.d/99-custom
|
||||
- Postwhite : /etc/postwhite.conf
|
||||
Feel free to suggest to add others!"""
|
||||
@@ -158,10 +160,21 @@ class Backup:
|
||||
self.config.getboolean("opendkim", "enabled")):
|
||||
dkim_keys = self.config.get(
|
||||
"opendkim", "keys_storage_dir", fallback="/var/lib/dkim")
|
||||
if os.path.isdir(dkim_keys):
|
||||
shutil.copytree(dkim_keys, os.path.join(custom_path, "dkim"))
|
||||
utils.printcolor(
|
||||
"DKIM keys saved!", utils.GREEN)
|
||||
|
||||
# Radicale Collections
|
||||
if (self.config.has_option("radicale", "enabled") and
|
||||
self.config.getboolean("radicale", "enabled")):
|
||||
radicale_backup = os.path.join(self.config.get(
|
||||
"radicale", "home_dir", fallback="/srv/radicale"), "collections")
|
||||
if os.path.isdir(radicale_backup):
|
||||
shutil.copytree(radicale_backup, os.path.join(
|
||||
custom_path, "radicale"))
|
||||
utils.printcolor("Radicale files saved", utils.GREEN)
|
||||
|
||||
# AMAVIS
|
||||
if (self.config.has_option("amavis", "enabled") and
|
||||
self.config.getboolean("amavis", "enabled")):
|
||||
|
||||
@@ -89,7 +89,7 @@ class Dovecot(base.Installer):
|
||||
def post_run(self):
|
||||
"""Additional tasks."""
|
||||
mail_dir = os.path.join(self.restore, "mails/")
|
||||
if self.restore and len(os.listdir(mail_dir)) > 0:
|
||||
if self.restore is not None and len(os.listdir(mail_dir)) > 0:
|
||||
utils.printcolor(
|
||||
"Copying mail backup over dovecot directory.", utils.GREEN)
|
||||
|
||||
@@ -103,7 +103,7 @@ class Dovecot(base.Installer):
|
||||
for filename in filenames:
|
||||
shutil.chown(os.path.join(dirpath, filename),
|
||||
self.user, self.user)
|
||||
elif self.restore:
|
||||
elif self.restore is not None:
|
||||
utils.printcolor(
|
||||
"It seems that mails were not backed up, skipping mail restoration.", utils.MAGENTA)
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ class Modoboa(base.Installer):
|
||||
self.config.get("amavis", "dbname"), self.dbuser)
|
||||
|
||||
def get_sql_schema_path(self):
|
||||
if self.restore:
|
||||
if self.restore is not None:
|
||||
db_dump_path = self._restore_database_dump("modoboa")
|
||||
if db_dump_path is not None:
|
||||
return db_dump_path
|
||||
|
||||
@@ -46,6 +46,18 @@ class Opendkim(base.Installer):
|
||||
stat.S_IROTH | stat.S_IXOTH,
|
||||
target[1], target[2]
|
||||
)
|
||||
# Restore dkim keys from backup if restoring
|
||||
if self.restore is not None:
|
||||
dkim_keys_backup = os.path.join(
|
||||
self.restore, "custom/dkim")
|
||||
if os.path.isdir(dkim_keys_backup):
|
||||
for file in os.listdir(dkim_keys_backup):
|
||||
file_path = os.path.join(dkim_keys_backup, file)
|
||||
if os.path.isfile(file_path):
|
||||
utils.copy_file(file_path, self.config.get(
|
||||
"opendkim", "keys_storage_dir", fallback="/var/lib/dkim"))
|
||||
utils.printcolor(
|
||||
"DKIM keys restored from backup", utils.GREEN)
|
||||
super(Opendkim, self).install_config_files()
|
||||
|
||||
def get_template_context(self):
|
||||
|
||||
@@ -47,13 +47,15 @@ class Postwhite(base.Installer):
|
||||
self.install_from_archive(SPF_TOOLS_REPOSITORY, install_dir)
|
||||
postw_dir = self.install_from_archive(
|
||||
POSTWHITE_REPOSITORY, install_dir)
|
||||
# Attempt to restore config file from backup
|
||||
if self.restore is not None:
|
||||
postwhite_backup_configuration = os.path.join(
|
||||
self.restore, "custom/postwhite.conf")
|
||||
if self.restore and os.path.isfile(postwhite_backup_configuration):
|
||||
utils.copy_file(postwhite_backup_configuration, "/etc")
|
||||
if os.path.isfile(postwhite_backup_configuration):
|
||||
utils.copy_file(postwhite_backup_configuration, self.config_dir)
|
||||
utils.printcolor(
|
||||
"postwhite.conf restored from backup", utils.GREEN)
|
||||
else:
|
||||
utils.copy_file(os.path.join(postw_dir, "postwhite.conf"), "/etc")
|
||||
utils.copy_file(os.path.join(postw_dir, "postwhite.conf"), self.config_dir)
|
||||
postw_bin = os.path.join(postw_dir, "postwhite")
|
||||
utils.exec_cmd("{} /etc/postwhite.conf".format(postw_bin))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Radicale related tasks."""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
|
||||
from .. import package
|
||||
@@ -70,6 +71,17 @@ class Radicale(base.Installer):
|
||||
stat.S_IROTH | stat.S_IXOTH,
|
||||
0, 0
|
||||
)
|
||||
# Attempt to restore radicale collections from backup
|
||||
if self.restore is not None:
|
||||
radicale_backup = os.path.join(
|
||||
self.restore, "custom/radicale")
|
||||
if os.path.isdir(radicale_backup):
|
||||
restore_target = os.path.join(self.home_dir, "collections")
|
||||
if os.path.isdir(restore_target):
|
||||
shutil.rmtree(restore_target)
|
||||
shutil.copytree(radicale_backup, restore_target)
|
||||
utils.printcolor(
|
||||
"Radicale collections restored from backup", utils.GREEN)
|
||||
super(Radicale, self).install_config_files()
|
||||
|
||||
def post_run(self):
|
||||
|
||||
@@ -25,7 +25,7 @@ class Spamassassin(base.Installer):
|
||||
|
||||
def get_sql_schema_path(self):
|
||||
"""Return SQL schema."""
|
||||
if self.restore:
|
||||
if self.restore is not None:
|
||||
db_dump_path = self._restore_database_dump("spamassassin")
|
||||
if db_dump_path is not None:
|
||||
return db_dump_path
|
||||
|
||||
Reference in New Issue
Block a user