diff options
author | xengineering <me@xengineering.eu> | 2021-10-10 12:19:42 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2021-10-10 12:19:42 +0200 |
commit | 553e726599edfd187b255132f7b9951734b12b38 (patch) | |
tree | ead1918e30818fac8165f4b9b9447ee0b86b3bcf | |
parent | b143bb0fc8ac9d8cc9a40e9bd92108ab3dcef11d (diff) | |
download | xbackup-553e726599edfd187b255132f7b9951734b12b38.tar xbackup-553e726599edfd187b255132f7b9951734b12b38.tar.zst xbackup-553e726599edfd187b255132f7b9951734b12b38.zip |
Breaking: Change Config File Structure for v1.0.0
-rw-r--r-- | config/debug.json | 8 | ||||
-rw-r--r-- | config/default.json | 8 | ||||
-rw-r--r-- | src/xbackup/backup.py | 18 | ||||
-rw-r--r-- | src/xbackup/prune.py | 4 | ||||
-rw-r--r-- | src/xbackup/script.py | 4 |
5 files changed, 23 insertions, 19 deletions
diff --git a/config/debug.json b/config/debug.json index 8f68241..0a0e6d2 100644 --- a/config/debug.json +++ b/config/debug.json @@ -1,7 +1,9 @@ { - "backup":{ - "backup_source":"fakeroot", - "borg_repos_folder":"fakeroot/var/lib/xbackup/borg", + "generic":{ + "borg_repos_folder":"fakeroot/var/lib/xbackup/borg" + }, + "paths":{ + "backup_root":"fakeroot", "blacklist":[ "dev/*", "lost+found/*", diff --git a/config/default.json b/config/default.json index 5285bf4..ecb6ce9 100644 --- a/config/default.json +++ b/config/default.json @@ -1,7 +1,9 @@ { - "backup":{ - "backup_source":"/", - "borg_repos_folder":"/var/lib/xbackup/borg", + "generic":{ + "borg_repos_folder":"/var/lib/xbackup/borg" + }, + "paths":{ + "backup_root":"/", "blacklist":[ "dev/*", "lost+found/*", diff --git a/src/xbackup/backup.py b/src/xbackup/backup.py index 7744e42..8378977 100644 --- a/src/xbackup/backup.py +++ b/src/xbackup/backup.py @@ -14,11 +14,11 @@ import os from xbackup.utils import POSITIVE_ANSWERS,shell -def backup(config, scripted): +def backup(generic_cfg, paths_cfg, scripted): """perform a file-based full system backup""" # generate all necessary paths based on config - paths = Filepaths(config) + paths = Filepaths(generic_cfg, paths_cfg) print(paths) # get confirmation from user if not in scripted execution mode @@ -38,14 +38,14 @@ def backup(config, scripted): class Filepaths(): """A Container Class to hold Filepaths for the Borg Backup Tool""" - def __init__(self, config): + def __init__(self, generic_cfg, paths_cfg): """The Constructor""" # parse backup source (usually / for system backups) - self.backup_source = config["backup_source"] + self.backup_root = paths_cfg["backup_root"] # parse folder for borg repositories - self.borg_repos_folder = config["borg_repos_folder"] + self.borg_repos_folder = generic_cfg["borg_repos_folder"] # path to the borg repository hostname = os.uname()[1] @@ -53,8 +53,8 @@ class Filepaths(): # create blacklist of folders to be excluded from the backup self.blacklist = [] - for entry in config["blacklist"]: - self.blacklist.append(os.path.join(self.backup_source, entry)) + for entry in paths_cfg["blacklist"]: + self.blacklist.append(os.path.join(self.backup_root, entry)) # avoid matroska-style backups of backups (yes, it is important) self.blacklist.append(self.borg_repos_folder) @@ -64,7 +64,7 @@ class Filepaths(): retval = "" - retval += "\nbackup_source:\n" + self.backup_source + "\n" + retval += "\nbackup_root:\n" + self.backup_root + "\n" retval += "\nblacklist:\n" for item in self.blacklist: @@ -86,7 +86,7 @@ def run_backup(paths): f"{paths.borg_repo}::'{{hostname}}-{{user}}-{{now:%Y-%m-%d_%H:%M:%S}}' \\" # set backup source - command += f"\n {paths.backup_source} \\" + command += f"\n {paths.backup_root} \\" # append blacklist elements for key,value in enumerate(paths.blacklist): diff --git a/src/xbackup/prune.py b/src/xbackup/prune.py index 79216a3..7e57830 100644 --- a/src/xbackup/prune.py +++ b/src/xbackup/prune.py @@ -13,12 +13,12 @@ import os from xbackup.utils import POSITIVE_ANSWERS,shell -def prune(backup_cfg, prune_cfg, scripted): +def prune(generic_cfg, prune_cfg, scripted): """prune backups""" # generate backup repository path hostname = os.uname()[1] - repo = os.path.join(backup_cfg["borg_repos_folder"], hostname) + repo = os.path.join(generic_cfg["borg_repos_folder"], hostname) # parse prune values hourly = prune_cfg["keep-hourly"] diff --git a/src/xbackup/script.py b/src/xbackup/script.py index 2c2521b..ae55c53 100644 --- a/src/xbackup/script.py +++ b/src/xbackup/script.py @@ -22,9 +22,9 @@ def run(): welcome() if args.command == "backup": - backup.backup(cfg["backup"], args.scripted) + backup.backup(cfg["generic"], cfg["paths"], args.scripted) elif args.command == "prune": - prune.prune(cfg["backup"], cfg["prune"], args.scripted) + prune.prune(cfg["generic"], cfg["prune"], args.scripted) else: print(f"Unknown command '{args.command}'") sys.exit(1) |