diff --git a/config-default.yml b/config-default.yml new file mode 100644 index 0000000..3956129 --- /dev/null +++ b/config-default.yml @@ -0,0 +1,7 @@ +# docker-vol-backup config +general: + compression: gz + archive_suffix: datatime + archive_path: /home + + \ No newline at end of file diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..46c874d --- /dev/null +++ b/config.yml @@ -0,0 +1,13 @@ +# docker-vol-backup config +general: + compression: bz2 + +stacks: + hedgedoc: + services: + - hedgedoc_database + - hedgedoc_app + volumes: + - hedgedoc_database + - hedgedoc_uploads + \ No newline at end of file diff --git a/volume-backup.py b/volume-backup.py index 2d80105..8e9ebc6 100644 --- a/volume-backup.py +++ b/volume-backup.py @@ -2,7 +2,19 @@ from python_on_whales import docker import datetime import sys import pathlib +import yaml +import collections.abc +def update(orig_dict, new_dict): + for key, val in new_dict.items(): + if isinstance(val, collections.abc.Mapping): + tmp = update(orig_dict.get(key, { }), val) + orig_dict[key] = tmp + elif isinstance(val, list): + orig_dict[key] = (orig_dict.get(key, []) + val) + else: + orig_dict[key] = new_dict[key] + return orig_dict now = "{date:%Y%m%d-%H%M%S}".format( date=datetime.datetime.now() ) @@ -20,7 +32,16 @@ volumes = [ (source_volume,"/volume"), print("Archive volume: ", source_volume, " to file: ", archive_path) -out=docker.run(image=image, - command=command, - volumes=volumes) +#out=docker.run(image=image, +# command=command, +# volumes=volumes) +with open("config.yml", mode="rt", encoding="utf-8") as file: + config = yaml.safe_load(file) +print(config) +with open("config-default.yml", mode="rt", encoding="utf-8") as file: + config_default = yaml.safe_load(file) +print(config_default) + +config = update(config_default, config) +print(config)