Skip to content
Snippets Groups Projects
Commit 1b9f7f22 authored by Radoslav Bodó's avatar Radoslav Bodó
Browse files

rwm: add autotags (add backup config name as tag for its backup snapshot), add...

rwm: add autotags (add backup config name as tag for its backup snapshot), add backup_extras (global options for restic backup)
parent 973c4eb9
No related branches found
No related tags found
No related merge requests found
Pipeline #7787 passed
......@@ -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"]
......@@ -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
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment