diff --git a/resticbackup/cli.py b/resticbackup/cli.py index 11c2cd9..e9213af 100644 --- a/resticbackup/cli.py +++ b/resticbackup/cli.py @@ -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)