diff --git a/examples/rwm-backups.conf b/examples/rwm-backups.conf index 6f8d7ae7aecec77bde69cd675a66c6bc8ecc59f2..8452345e0025c14cb1edf878678eeb01e359db5d 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 94f302de56d244a8fc368006a1aedb8a699941b7..76cc9aa544d4a39e52e799f6de15d358ba58c064 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 e383ee87fe47d3813bf895f4a16deaa83b0b48f8..6c22223fde51f496bfe27cab6a13d13d95cdb523 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": {