diff --git a/examples/rwm-backups.conf b/examples/rwm-backups.conf index 8452345e0025c14cb1edf878678eeb01e359db5d..07464d2a9393a34eb4dee54cd27827a84bd65b47 100644 --- a/examples/rwm-backups.conf +++ b/examples/rwm-backups.conf @@ -18,8 +18,6 @@ backups: - "/var/lib/mysql/*" - "/var/lib/postgresql/*" - "/var/run/*" - tags: - - "simplefs" extras: - "--one-file-system" @@ -27,7 +25,7 @@ backups: filesdirs: - /var/lib/rwm/mysql.tar.gz tags: - - "mysql" + - "database" prerun: - "/opt/rwm/scripts/backup_mysql.py create" postrun: @@ -37,3 +35,6 @@ retention: keep-daily: "60" keep-within: "60d" keep-tag: "donotforget" + +autotags: true +backup_extras: ["--pack-size", "64"] diff --git a/rwm.py b/rwm.py index d08c851e3da469ad8701ec997283d864b315720b..028b4a6713a7d30aaf7238a467a05091be824a45 100755 --- a/rwm.py +++ b/rwm.py @@ -133,10 +133,20 @@ class RWMConfig(BaseModel): retention: Dictionary containing retention policies for Restic repository. - Keys and values corresponds to a `restic forget` command `--keep*` options without leading dashes. + Keys and values corresponds to a `restic forget` command `--keep*` + options without leading dashes. lock_path: - Path for parallel execution exclusion lock. Defaults to `/var/run/rwm.lock`. + Path for parallel execution exclusion lock. Defaults to + `/var/run/rwm.lock`. + + autotags: + Automatically add a tag to each backup snapshot, using the value + of the backup configuration name. + + backup_extras: + Additional options for any the `restic backup` commmand (eg. default `pack-size` setting). + Defaults to an empty list. """ model_config = ConfigDict(extra='forbid') @@ -149,6 +159,8 @@ class RWMConfig(BaseModel): backups: Dict[str, BackupConfig] = {} retention: Dict[str, str] = {} lock_path: str = "/var/run/rwm.lock" + autotags: bool = False + backup_extras: List[str] = [] class RwmJSONEncoder(json.JSONEncoder): @@ -592,15 +604,24 @@ class RWM: logger.info(f"_restic_backup {name}") conf = self.config.backups[name] - excludes = [] - for item in conf.excludes: - excludes += ["--exclude", item] - tags = [] + if self.config.autotags: + tags += ["--tag", name] for item in conf.tags: tags += ["--tag", item] - cmd_args = ["backup"] + conf.extras + tags + excludes + conf.filesdirs + excludes = [] + for item in conf.excludes: + excludes += ["--exclude", item] + + cmd_args = [ + "backup", + *self.config.backup_extras, + *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 3a89a5b3f0bb1d27b561fe64e6d798f53831ff32..d7c18296b24c7e9a98d68e4dbd6831d595d3793f 100644 --- a/tests/test_rwm.py +++ b/tests/test_rwm.py @@ -136,6 +136,8 @@ def test_backup(tmpworkdir: str, motoserver: str): # pylint: disable=unused-arg "keep-daily": "1" }, "lock_path": f"{tmpworkdir}/rwm.lock", + "autotags": True, + "backup_extras": ["--quiet", "false"] # dummy here }) Path("testdatadir").mkdir()