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