From 2acfbf243465a8864b1482271226a44517ee47f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radoslav=20Bod=C3=B3?= <bodik@cesnet.cz> Date: Wed, 17 Apr 2024 08:40:52 +0200 Subject: [PATCH] rwm: add tags to backup config --- examples/rwm-backups.conf | 16 ++++++---------- rwm.py | 12 +++++++++++- tests/test_rwm.py | 3 ++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/examples/rwm-backups.conf b/examples/rwm-backups.conf index 6f8d7ae..8452345 100644 --- a/examples/rwm-backups.conf +++ b/examples/rwm-backups.conf @@ -18,25 +18,21 @@ backups: - "/var/lib/mysql/*" - "/var/lib/postgresql/*" - "/var/run/*" - extras: ["--one-file-system", "--tag", "simplefs"] + tags: + - "simplefs" + extras: + - "--one-file-system" mysql: filesdirs: - /var/lib/rwm/mysql.tar.gz - extras: ["--tag", "mysql"] + tags: + - "mysql" prerun: - "/opt/rwm/scripts/backup_mysql.py create" postrun: - "/opt/rwm/scripts/backup_mysql.py cleanup" - nas: - filesdirs: - - /mnt/nas - prerun: - - mount - postrun: - - unmount - retention: keep-daily: "60" keep-within: "60d" diff --git a/rwm.py b/rwm.py index 94f302d..76cc9aa 100755 --- a/rwm.py +++ b/rwm.py @@ -79,6 +79,9 @@ class BackupConfig(BaseModel): excludes: List of patterns for `--exclude` options for `restic backup` commmand. Defaults to an empty list. + tags: + List of tags for the new backup snapshot. Defaults to an empty list. + extras: Additional options for the `restic backup` commmand. Defaults to an empty list. @@ -93,6 +96,7 @@ class BackupConfig(BaseModel): filesdirs: List[str] excludes: List[str] = [] + tags: List[str] = [] extras: List[str] = [] prerun: List[str] = [] postrun: List[str] = [] @@ -552,10 +556,16 @@ class RWM: logger.info(f"_restic_backup {name}") conf = self.config.backups[name] + excludes = [] for item in conf.excludes: excludes += ["--exclude", item] - cmd_args = ["backup"] + conf.extras + excludes + conf.filesdirs + + tags = [] + for item in conf.tags: + tags += ["--tag", item] + + cmd_args = ["backup"] + conf.extras + tags + excludes + conf.filesdirs wrap_output(backup_proc := self.restic_cmd(cmd_args)) return backup_proc.returncode diff --git a/tests/test_rwm.py b/tests/test_rwm.py index e383ee8..6c22223 100644 --- a/tests/test_rwm.py +++ b/tests/test_rwm.py @@ -128,7 +128,8 @@ def test_backup(tmpworkdir: str, motoserver: str): # pylint: disable=unused-arg "testcfg": { "filesdirs": ["testdatadir/"], "excludes": ["testfile_to_be_ignored"], - "extras": ["--tag", "dummytag"], + "tags": ["dummytag"], + "extras": ["--one-file-system"], } }, "retention": { -- GitLab