add option to touch a file when a backup completes successfully
This commit is contained in:
parent
1b1200a8e3
commit
def79761fa
@ -4,7 +4,8 @@ import subprocess
|
||||
from socket import getfqdn
|
||||
|
||||
from resticbackup.types import ClientConfig, load_config, load_base_config, list_configs
|
||||
from resticbackup.lib import ExecWrapper, init_ok, die, pdie, checkp, get_retention_args, get_newest_snapshot
|
||||
from resticbackup.lib import ExecWrapper, init_ok, die, pdie, checkp, get_retention_args, \
|
||||
get_newest_snapshot, touch_statefile
|
||||
|
||||
|
||||
def cmd_backup(args, parser):
|
||||
@ -45,16 +46,19 @@ def cmd_backup(args, parser):
|
||||
|
||||
# perform retention
|
||||
retention_args = get_retention_args(config.backup.schedule)
|
||||
if not retention_args:
|
||||
return
|
||||
if retention_args:
|
||||
forget_cmd = ["forget", "--group-by", "tags"] + retention_args
|
||||
for k, v in retention_tags.items():
|
||||
forget_cmd.extend(["--tag", "{}={}".format(k, v)])
|
||||
checkp(config.run(forget_cmd))
|
||||
|
||||
forget_cmd = ["forget", "--group-by", "tags"] + retention_args
|
||||
for k, v in retention_tags.items():
|
||||
forget_cmd.extend(["--tag", "{}={}".format(k, v)])
|
||||
checkp(config.run(forget_cmd))
|
||||
# perform junk deletion
|
||||
checkp(config.run(["prune"]))
|
||||
|
||||
# perform junk deletion
|
||||
return pdie(config.run(["prune"]))
|
||||
# touch if necessary
|
||||
if config.touch_complete:
|
||||
path = config.touch_complete.format(name=args.name)
|
||||
touch_statefile(path)
|
||||
|
||||
|
||||
def cmd_restore(args, parser):
|
||||
|
@ -1,3 +1,4 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import subprocess
|
||||
@ -124,3 +125,14 @@ def get_retention_args(schedule):
|
||||
return cmd or None
|
||||
else:
|
||||
raise Exception("unknown retention function {}".format(mode))
|
||||
|
||||
|
||||
def touch_statefile(path):
|
||||
d = os.path.dirname(path)
|
||||
if not os.path.exists(d):
|
||||
os.makedirs(d)
|
||||
if os.path.exists(path):
|
||||
os.utime(path)
|
||||
else:
|
||||
with open(path, "w"):
|
||||
pass
|
||||
|
@ -67,6 +67,7 @@ class ClientConfig:
|
||||
server_type: str
|
||||
uri: str
|
||||
secret: str
|
||||
touch_complete: str
|
||||
backup: BackupConfig
|
||||
|
||||
@property
|
||||
@ -89,7 +90,16 @@ class ClientConfig:
|
||||
server_type, server = main["server"].split(":", 1)
|
||||
if server_type != "s3":
|
||||
raise Exception("unsupported server type: {}".format(server_type))
|
||||
return ClientConfig(server_type=server_type, uri=urlparse(server), secret=main["secret"], backup=backup)
|
||||
touch_path = main.get("touch_complete")
|
||||
if touch_path is not None and not touch_path.startswith("/"):
|
||||
raise Exception("touch path must be absolute: {}".format(touch_path))
|
||||
return ClientConfig(
|
||||
server_type=server_type,
|
||||
uri=urlparse(server),
|
||||
secret=main["secret"],
|
||||
touch_complete=touch_path,
|
||||
backup=backup
|
||||
)
|
||||
|
||||
def run(self, args, **kwargs):
|
||||
env = dict(os.environ)
|
||||
|
Loading…
x
Reference in New Issue
Block a user