From 5eb04a0fbe22fc6fb4a5e1e2bd79f81daa49c787 Mon Sep 17 00:00:00 2001 From: miklobit Date: Tue, 7 Feb 2023 01:18:21 +0100 Subject: [PATCH] add config --- config-default.yml | 7 +++++++ config.yml | 13 +++++++++++++ volume-backup.py | 27 ++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 config-default.yml create mode 100644 config.yml 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)