bash option
This commit is contained in:
@@ -24,7 +24,7 @@ def install(appname, config, upgrade):
|
||||
utils.printcolor(u"{}".format(inst), utils.RED)
|
||||
sys.exit(1)
|
||||
|
||||
def backup(config):
|
||||
def backup(config, isBash):
|
||||
"""Backup instance"""
|
||||
try:
|
||||
script = importlib.import_module(
|
||||
@@ -32,7 +32,7 @@ def backup(config):
|
||||
except ImportError:
|
||||
print("Error importing backup")
|
||||
try:
|
||||
getattr(script, "Backup")(config).run()
|
||||
getattr(script, "Backup")(config, isBash).run()
|
||||
except utils.FatalError as inst:
|
||||
utils.printcolor(u"{}".format(inst), utils.RED)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -4,6 +4,7 @@ import os
|
||||
import pwd
|
||||
import shutil
|
||||
import stat
|
||||
import datetime
|
||||
|
||||
from .. import database
|
||||
from .. import utils
|
||||
@@ -26,8 +27,9 @@ class Backup():
|
||||
#||--> mails
|
||||
# |--> vmails
|
||||
|
||||
def __init__(self, config):
|
||||
def __init__(self, config, isBash):
|
||||
self.config = config
|
||||
self.isBash = isBash
|
||||
self.destinationPath = ""
|
||||
self.BACKUPDIRECTORY = ["mails/", "custom/", "databases/"]
|
||||
|
||||
@@ -49,17 +51,19 @@ class Backup():
|
||||
return False
|
||||
|
||||
if not os.path.exists(path):
|
||||
createDir = input(f"\"{path}\" doesn't exists, would you like to create it ? [Y/n]\n").lower()
|
||||
if not self.isBash:
|
||||
createDir = input(f"\"{path}\" doesn't exists, would you like to create it ? [Y/n]\n").lower()
|
||||
|
||||
if createDir == "y" or createDir == "yes":
|
||||
if self.isBash or (not self.isBash and (createDir == "y" or createDir == "yes")):
|
||||
pw = pwd.getpwnam("root")
|
||||
utils.mkdir_safe(path, stat.S_IRWXU | stat.S_IRWXG, pw[2], pw[3])
|
||||
else:
|
||||
return False
|
||||
|
||||
if len(os.listdir(path)) != 0:
|
||||
delDir = input("Warning : backup folder is not empty, it will be purged if you continue... [Y/n]").lower()
|
||||
if delDir == "y" or delDir == "yes":
|
||||
if not self.isBash:
|
||||
delDir = input("Warning : backup folder is not empty, it will be purged if you continue... [Y/n]\n").lower()
|
||||
if self.isBash or (not self.isBash and (delDir == "y" or delDir == "yes")):
|
||||
shutil.rmtree(path)
|
||||
else:
|
||||
return False
|
||||
@@ -75,11 +79,16 @@ class Backup():
|
||||
|
||||
def setPath(self):
|
||||
"""Setup backup directory"""
|
||||
user_value = None
|
||||
while (user_value == '' or user_value == None or not self.validatePath(user_value)):
|
||||
print("Enter backup path, please provide an empty folder.")
|
||||
print("CTRL+C to cancel")
|
||||
user_value = utils.user_input("-> ")
|
||||
if self.isBash:
|
||||
date = datetime.datetime.now().strftime("%m_%d_%Y_%H_%M")
|
||||
path = f"/modoboa_backup/backup_{date}/"
|
||||
self.validatePath(path)
|
||||
else:
|
||||
user_value = None
|
||||
while (user_value == '' or user_value == None or not self.validatePath(user_value)):
|
||||
print("Enter backup path, please provide an empty folder.")
|
||||
print("CTRL+C to cancel")
|
||||
user_value = utils.user_input("-> ")
|
||||
|
||||
|
||||
def backupConfigFile(self):
|
||||
|
||||
5
run.py
5
run.py
@@ -80,6 +80,9 @@ def main(input_args):
|
||||
parser.add_argument(
|
||||
"--beta", action="store_true", default=False,
|
||||
help="Install latest beta release of Modoboa instead of the stable one")
|
||||
parser.add_argument(
|
||||
"--bash", action="store_true", default=False,
|
||||
help="(backup only) - For script usage, No interaction will be required")
|
||||
parser.add_argument("domain", type=str,
|
||||
help="The main domain of your future mail server")
|
||||
args = parser.parse_args(input_args)
|
||||
@@ -104,7 +107,7 @@ def main(input_args):
|
||||
upgrade_disclaimer(config)
|
||||
elif args.backup:
|
||||
backup_disclamer()
|
||||
scripts.backup(config)
|
||||
scripts.backup(config, args.bash)
|
||||
return
|
||||
else:
|
||||
installation_disclaimer(args, config)
|
||||
|
||||
Reference in New Issue
Block a user