diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/setup.py | 2 | ||||
-rw-r--r-- | src/xbackup/backup.py | 14 | ||||
-rw-r--r-- | src/xbackup/script.py | 16 |
3 files changed, 25 insertions, 7 deletions
diff --git a/src/setup.py b/src/setup.py index b47026d..0d8e17f 100644 --- a/src/setup.py +++ b/src/setup.py @@ -12,7 +12,7 @@ from distutils.core import setup setup(name="xbackup", - version="0.1.0", + version="0.2.0", description="Convenience wrapper around the Borg backup tool", author="xengineering", author_email="me@xengineering.eu", diff --git a/src/xbackup/backup.py b/src/xbackup/backup.py index b3b5a0b..25b26f1 100644 --- a/src/xbackup/backup.py +++ b/src/xbackup/backup.py @@ -11,13 +11,23 @@ import sys import subprocess -def backup(config): +POSITIVE_ANSWERS = ["Y", "y", "Yes", "yes", "YES"] + + +def backup(config, scripted): """perform a file-based full system backup""" # generate all necessary paths based on config paths = Filepaths(config) print(paths) + # get confirmation from user if not in scripted execution mode + if not scripted: + answer = input("\nDo you want to continue? [y/N] ") + if answer not in POSITIVE_ANSWERS: + print("\nTerminated.") + sys.exit(0) + # init borg repository (accepting failure on already existing repo) shell(f"borg init -e none {paths.borg_repo}", panic=False) @@ -60,7 +70,7 @@ class Filepaths(): for item in self.blacklist: retval += item + "\n" - retval += "\nborg_repo:\n" + self.borg_repo + "\n" + retval += "\nborg_repo:\n" + self.borg_repo return retval diff --git a/src/xbackup/script.py b/src/xbackup/script.py index 272894f..d262fd5 100644 --- a/src/xbackup/script.py +++ b/src/xbackup/script.py @@ -21,7 +21,7 @@ def run(): welcome() if args.command == "backup": - backup.backup(cfg["backup"]) + backup.backup(cfg["backup"], args.scripted) else: print(f"Unknown command '{args.command}'") sys.exit(1) @@ -40,19 +40,27 @@ def parse_arguments(): "Project page: https://gitea.xengineering.eu/xengineering/xbackup", ) - # positional arguments + # main command argument (positional) parser.add_argument("command", type=str, help="the action to be performed", - choices=["backup"], + choices=["backup"] ) - # optional arguments + # path to configuration file (optional) parser.add_argument("-c", "--config", type=str, metavar="CONFIG", help="path to the JSON configuration file", default="/etc/xbackup/config.json", ) + # flag for scripted execution (optional) + parser.add_argument("-s", "--script", + dest="scripted", + action="store_true", + help="use this flag to enable a non-interactive mode" + ) + parser.set_defaults(scripted=False) + # argument parsing args = parser.parse_args() return args |