add exec mode

This commit is contained in:
dave 2022-12-11 21:26:26 -08:00
parent 55c699d90f
commit d8046ae41b

View File

@ -161,6 +161,19 @@ def cmd_restore(args, parser):
pass # TODO
def cmd_exec(args, parser):
config, backup_configs = load_configs()
try:
backup_config = backup_configs[args.name]
except KeyError:
die("invalid backup name: '{}'".format(args.name))
env = dict(os.environ)
env.update(**config.env)
subprocess.Popen(["restic"] + args.args, env=env).wait()
def main():
parser = argparse.ArgumentParser(description="restic wrapper")
@ -174,6 +187,11 @@ def main():
p_backup.set_defaults(func=cmd_backup)
p_backup.add_argument("name", help="name of backup to execute")
p_exec = sp_action.add_parser("exec", help="execute a restic command")
p_exec.set_defaults(func=cmd_exec)
p_exec.add_argument("name", help="name of backup to configure restic for")
p_exec.add_argument("args", nargs="+", help="command arguments")
args = parser.parse_args()
args.func(args, parser)