Few fixes
This commit is contained in:
@@ -102,7 +102,7 @@ class Amavis(base.Installer):
|
||||
if os.path.isfile(amavis_custom):
|
||||
utils.copy_file(amavis_custom, path)
|
||||
utils.success("Amavis custom configuration saved!")
|
||||
backup("spamassassin", path)
|
||||
backup("spamassassin", self.config, os.path.dirname(path))
|
||||
|
||||
def restore(self):
|
||||
"""Restore custom config files."""
|
||||
|
||||
@@ -161,6 +161,10 @@ class Installer(object):
|
||||
custom_backup_path = os.path.join(path, "custom")
|
||||
self.custom_backup(custom_backup_path)
|
||||
|
||||
def custom_backup(self, path):
|
||||
"""Override this method in subscripts to add custom backup content."""
|
||||
pass
|
||||
|
||||
def restore(self):
|
||||
"""Restore from a previous backup."""
|
||||
pass
|
||||
|
||||
@@ -137,28 +137,30 @@ class Dovecot(base.Installer):
|
||||
|
||||
def backup(self, path):
|
||||
"""Backup emails."""
|
||||
home_dir = self.config.get("dovecot", "home_dir")
|
||||
utils.printcolor("Backing up mails", utils.MAGENTA)
|
||||
if not os.path.exists(self.home_dir) or os.path.isfile(self.home_dir):
|
||||
utils.printcolor("Error backing up emails, provided path "
|
||||
f" ({self.home_dir}) seems not right...", utils.RED)
|
||||
if not os.path.exists(home_dir) or os.path.isfile(home_dir):
|
||||
utils.error("Error backing up emails, provided path "
|
||||
f" ({home_dir}) seems not right...")
|
||||
return
|
||||
|
||||
dst = os.path.join(path, "mails/")
|
||||
if os.path.exists(dst):
|
||||
shutil.rmtree(dst)
|
||||
shutil.copytree(self.home_dir, dst)
|
||||
utils.printcolor("Mail backup complete!", utils.GREEN)
|
||||
shutil.copytree(home_dir, dst)
|
||||
utils.success("Mail backup complete!")
|
||||
|
||||
def restore(self):
|
||||
"""Restore emails."""
|
||||
home_dir = self.config.get("dovecot", "home_dir")
|
||||
mail_dir = os.path.join(self.restore, "mails/")
|
||||
if len(os.listdir(mail_dir)) > 0:
|
||||
utils.success("Copying mail backup over dovecot directory.")
|
||||
if os.path.exists(self.home_dir):
|
||||
shutil.rmtree(self.home_dir)
|
||||
shutil.copytree(mail_dir, self.home_dir)
|
||||
if os.path.exists(home_dir):
|
||||
shutil.rmtree(home_dir)
|
||||
shutil.copytree(mail_dir, home_dir)
|
||||
# Resetting permission for vmail
|
||||
for dirpath, dirnames, filenames in os.walk(self.home_dir):
|
||||
for dirpath, dirnames, filenames in os.walk(home_dir):
|
||||
shutil.chown(dirpath, self.user, self.user)
|
||||
for filename in filenames:
|
||||
shutil.chown(os.path.join(dirpath, filename),
|
||||
|
||||
@@ -101,4 +101,4 @@ class Postfix(base.Installer):
|
||||
|
||||
def backup(self, path):
|
||||
"""Launch postwhite backup."""
|
||||
backup("postwhite", path)
|
||||
backup("postwhite", self.config, path)
|
||||
|
||||
20
run.py
20
run.py
@@ -64,9 +64,9 @@ def upgrade_disclaimer(config):
|
||||
def backup_disclaimer():
|
||||
"""Display backup disclamer. """
|
||||
utils.printcolor(
|
||||
"Your mail server will be backed up (messages and databases) locally."
|
||||
" !! You should really transfer the backup somewhere else..."
|
||||
" Custom configuration (like to postfix) won't be saved.", utils.BLUE)
|
||||
"Your mail server will be backed up locally.\n"
|
||||
" !! You should really transfer the backup somewhere else...\n"
|
||||
" !! Custom configuration (like for postfix) won't be saved.", utils.BLUE)
|
||||
|
||||
|
||||
def restore_disclaimer():
|
||||
@@ -91,7 +91,7 @@ def backup_system(config, args):
|
||||
path = os.path.join(path, f"backup_{date}")
|
||||
else:
|
||||
path = args.backup_path
|
||||
backup_path = utils.validate_backup_path(path)
|
||||
backup_path = utils.validate_backup_path(path, args.silent_backup)
|
||||
if not backup_path:
|
||||
utils.printcolor(f"Path provided: {path}", utils.BLUE)
|
||||
return
|
||||
@@ -104,7 +104,9 @@ def backup_system(config, args):
|
||||
)
|
||||
utils.printcolor("CTRL+C to cancel", utils.MAGENTA)
|
||||
user_value = utils.user_input("-> ")
|
||||
backup_path = utils.validate_backup_path(user_value)
|
||||
if not user_value:
|
||||
continue
|
||||
backup_path = utils.validate_backup_path(user_value, args.silent_backup)
|
||||
|
||||
# Backup configuration file
|
||||
utils.copy_file(args.configfile, backup_path)
|
||||
@@ -119,8 +121,6 @@ def main(input_args):
|
||||
versions = (
|
||||
["latest"] + list(compatibility_matrix.COMPATIBILITY_MATRIX.keys())
|
||||
)
|
||||
parser.add_argument("--backup", action="store_true", default=False,
|
||||
help="Backing up interactively previously installed instance")
|
||||
parser.add_argument("--debug", action="store_true", default=False,
|
||||
help="Enable debug output")
|
||||
parser.add_argument("--force", action="store_true", default=False,
|
||||
@@ -145,6 +145,10 @@ def main(input_args):
|
||||
parser.add_argument(
|
||||
"--backup-path", type=str, metavar="path",
|
||||
help="To use with --silent-backup, you must provide a valid path")
|
||||
parser.add_argument(
|
||||
"--backup", action="store_true", default=False,
|
||||
help="Backing up interactively previously installed instance"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--silent-backup", action="store_true", default=False,
|
||||
help="For script usage, do not require user interaction "
|
||||
@@ -176,7 +180,7 @@ def main(input_args):
|
||||
is_config_file_available = utils.check_config_file(
|
||||
args.configfile, args.interactive, args.upgrade, args.backup, is_restoring)
|
||||
|
||||
if is_config_file_available and args.backup:
|
||||
if not is_config_file_available and (args.upgrade or args.backup):
|
||||
utils.error("No config file found,")
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user