WIP: Improved backup/restore system.
This commit is contained in:
101
run.py
101
run.py
@@ -3,6 +3,7 @@
|
||||
"""An installer for Modoboa."""
|
||||
|
||||
import argparse
|
||||
import datetime
|
||||
import os
|
||||
try:
|
||||
import configparser
|
||||
@@ -11,6 +12,7 @@ except ImportError:
|
||||
import sys
|
||||
|
||||
from modoboa_installer import compatibility_matrix
|
||||
from modoboa_installer import constants
|
||||
from modoboa_installer import package
|
||||
from modoboa_installer import scripts
|
||||
from modoboa_installer import ssl
|
||||
@@ -18,6 +20,19 @@ from modoboa_installer import system
|
||||
from modoboa_installer import utils
|
||||
|
||||
|
||||
PRIMARY_APPS = [
|
||||
"amavis",
|
||||
"modoboa",
|
||||
"automx",
|
||||
"radicale",
|
||||
"uwsgi",
|
||||
"nginx",
|
||||
"opendkim",
|
||||
"postfix",
|
||||
"dovecot"
|
||||
]
|
||||
|
||||
|
||||
def installation_disclaimer(args, config):
|
||||
"""Display installation disclaimer."""
|
||||
hostname = config.get("general", "hostname")
|
||||
@@ -58,10 +73,46 @@ def restore_disclaimer():
|
||||
"""Display restore disclamer. """
|
||||
utils.printcolor(
|
||||
"You are about to restore a previous installation of Modoboa."
|
||||
"If a new version has been released in between, please update your database !",
|
||||
"If a new version has been released in between, please update your database!",
|
||||
utils.BLUE)
|
||||
|
||||
|
||||
def backup_system(config, args):
|
||||
"""Launch backup procedure."""
|
||||
backup_disclaimer()
|
||||
backup_path = None
|
||||
if args.silent_backup:
|
||||
if not args.backup_path:
|
||||
if config.has_option("backup", "default_path"):
|
||||
path = config.get("backup", "default_path")
|
||||
else:
|
||||
path = constants.DEFAULT_BACKUP_DIRECTORY
|
||||
date = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M")
|
||||
path = os.path.join(path, f"backup_{date}")
|
||||
else:
|
||||
path = args.backup_path
|
||||
backup_path = utils.validate_backup_path(path)
|
||||
if not backup_path:
|
||||
utils.printcolor(f"Path provided: {path}", utils.BLUE)
|
||||
return
|
||||
else:
|
||||
user_value = None
|
||||
while not user_value or not backup_path:
|
||||
utils.printcolor(
|
||||
"Enter backup path (it must be an empty directory)",
|
||||
utils.MAGENTA
|
||||
)
|
||||
utils.printcolor("CTRL+C to cancel", utils.MAGENTA)
|
||||
user_value = utils.user_input("-> ")
|
||||
backup_path = utils.validate_backup_path(user_value)
|
||||
|
||||
# Backup configuration file
|
||||
utils.copy_file(args.configfile, backup_path)
|
||||
# Backup applications
|
||||
for app in PRIMARY_APPS:
|
||||
scripts.backup(app, config, backup_path)
|
||||
|
||||
|
||||
def main(input_args):
|
||||
"""Install process."""
|
||||
parser = argparse.ArgumentParser()
|
||||
@@ -98,9 +149,6 @@ def main(input_args):
|
||||
"--silent-backup", action="store_true", default=False,
|
||||
help="For script usage, do not require user interaction "
|
||||
"backup will be saved at ./modoboa_backup/Backup_M_Y_d_H_M if --backup-path is not provided")
|
||||
parser.add_argument(
|
||||
"--no-mail-backup", action="store_true", default=False,
|
||||
help="Disable mail backup (save space)")
|
||||
parser.add_argument(
|
||||
"--restore", type=str, metavar="path",
|
||||
help="Restore a previously backup up modoboa instance on a NEW machine. "
|
||||
@@ -117,17 +165,19 @@ def main(input_args):
|
||||
is_restoring = False
|
||||
if args.restore is not None:
|
||||
is_restoring = True
|
||||
args.configfile = os.path.join(args.restore, "installer.cfg")
|
||||
args.configfile = os.path.join(args.restore, args.configfile)
|
||||
if not os.path.exists(args.configfile):
|
||||
utils.printcolor("installer.cfg from backup not found!", utils.RED)
|
||||
utils.error(
|
||||
"Installer configuration file not found in backup!"
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
utils.printcolor("Welcome to Modoboa installer!\n", utils.GREEN)
|
||||
utils.success("Welcome to Modoboa installer!\n")
|
||||
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:
|
||||
utils.printcolor("No config file found,", utils.RED)
|
||||
utils.error("No config file found,")
|
||||
return
|
||||
|
||||
if args.stop_after_configfile_check:
|
||||
@@ -142,14 +192,14 @@ def main(input_args):
|
||||
config.set("dovecot", "domain", args.domain)
|
||||
config.set("modoboa", "version", args.version)
|
||||
config.set("modoboa", "install_beta", str(args.beta))
|
||||
|
||||
if args.backup or args.silent_backup:
|
||||
backup_system(config, args)
|
||||
return
|
||||
|
||||
# Display disclaimer python 3 linux distribution
|
||||
if args.upgrade:
|
||||
upgrade_disclaimer(config)
|
||||
elif args.backup or args.silent_backup:
|
||||
backup_disclaimer()
|
||||
scripts.backup(config, args.silent_backup,
|
||||
args.backup_path, args.no_mail_backup)
|
||||
return
|
||||
elif args.restore:
|
||||
restore_disclaimer()
|
||||
scripts.restore_prep(args.restore)
|
||||
@@ -175,33 +225,26 @@ def main(input_args):
|
||||
utils.printcolor(
|
||||
"The process can be long, feel free to take a coffee "
|
||||
"and come back later ;)", utils.BLUE)
|
||||
utils.printcolor("Starting...", utils.GREEN)
|
||||
utils.success("Starting...")
|
||||
package.backend.prepare_system()
|
||||
package.backend.install_many(["sudo", "wget"])
|
||||
ssl_backend = ssl.get_backend(config)
|
||||
if ssl_backend and not args.upgrade:
|
||||
ssl_backend.generate_cert()
|
||||
scripts.install("amavis", config, args.upgrade, args.restore)
|
||||
scripts.install("modoboa", config, args.upgrade, args.restore)
|
||||
scripts.install("automx", config, args.upgrade, args.restore)
|
||||
scripts.install("radicale", config, args.upgrade, args.restore)
|
||||
scripts.install("uwsgi", config, args.upgrade, args.restore)
|
||||
scripts.install("nginx", config, args.upgrade, args.restore)
|
||||
scripts.install("opendkim", config, args.upgrade, args.restore)
|
||||
scripts.install("postfix", config, args.upgrade, args.restore)
|
||||
scripts.install("dovecot", config, args.upgrade, args.restore)
|
||||
for appname in PRIMARY_APPS:
|
||||
scripts.install(appname, config, args.upgrade, args.restore)
|
||||
system.restart_service("cron")
|
||||
package.backend.restore_system()
|
||||
if not args.restore:
|
||||
utils.printcolor(
|
||||
utils.success(
|
||||
"Congratulations! You can enjoy Modoboa at https://{} (admin:password)"
|
||||
.format(config.get("general", "hostname")),
|
||||
utils.GREEN)
|
||||
.format(config.get("general", "hostname"))
|
||||
)
|
||||
else:
|
||||
utils.printcolor(
|
||||
utils.success(
|
||||
"Restore complete! You can enjoy Modoboa at https://{} (same credentials as before)"
|
||||
.format(config.get("general", "hostname")),
|
||||
utils.GREEN)
|
||||
.format(config.get("general", "hostname"))
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user