From f288f77aa4e64f0e7ae8449a081928d3e16d3f94 Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Wed, 4 Dec 2019 03:12:36 +0100 Subject: [PATCH] rcb snapshots --- restic_compose_backup/cli.py | 11 ++++++++++- restic_compose_backup/restic.py | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/restic_compose_backup/cli.py b/restic_compose_backup/cli.py index 4cec6d7..e3f094b 100644 --- a/restic_compose_backup/cli.py +++ b/restic_compose_backup/cli.py @@ -23,6 +23,9 @@ def main(): if args.action == 'status': status(config, containers) + if args.action == 'snapshots': + snapshots(config, containers) + elif args.action == 'backup': backup(config, containers) @@ -56,6 +59,12 @@ def status(config, containers): logger.info("-" * 67) +def snapshots(config, containers): + """Display restic snapshots""" + stdout, stderr = restic.snapshots(config.repository) + for line in stdout.decode().split('\n'): + logger.info('| %s', line) + def backup(config, containers): """Request a backup to start""" @@ -134,7 +143,7 @@ def parse_args(): parser = argparse.ArgumentParser(prog='restic_compose_backup') parser.add_argument( 'action', - choices=['status', 'backup', 'start-backup-process'], + choices=['status', 'snapshots', 'backup', 'start-backup-process'], ) parser.add_argument( '--log-level', diff --git a/restic_compose_backup/restic.py b/restic_compose_backup/restic.py index 218ccd2..030ec9c 100644 --- a/restic_compose_backup/restic.py +++ b/restic_compose_backup/restic.py @@ -2,7 +2,7 @@ Restic commands """ import logging -from typing import List +from typing import List, Tuple from subprocess import Popen, PIPE from restic_compose_backup import commands @@ -57,8 +57,8 @@ def backup_from_stdin(repository: str, filename: str, source_command: List[str]) return 0 if (source_exit == 0 and dest_exit == 0) else 1 -def snapshots(repository: str): - return commands.run(restic(repository, [ +def snapshots(repository: str) -> Tuple[str, str]: + return commands.run_capture_std(restic(repository, [ "snapshots", ]))