diff --git a/src/restic/backup.py b/src/restic/backup.py index 2c74516..d43fc9c 100755 --- a/src/restic/backup.py +++ b/src/restic/backup.py @@ -8,7 +8,7 @@ from rich.console import Console from rich.logging import RichHandler from rich.progress import Progress -from restic import snapshots +from restic import size, snapshots from restic.console import console, logger from restic.docker import manage_containers from restic.loki import send_to_loki @@ -92,6 +92,7 @@ def main( console.print_exception() else: snapshots.run(loki_url) + size.get_size(loki_url) if __name__ == '__main__': diff --git a/src/restic/size.py b/src/restic/size.py new file mode 100644 index 0000000..344e7c4 --- /dev/null +++ b/src/restic/size.py @@ -0,0 +1,26 @@ +import subprocess + +import click + +from restic.console import logger +from restic.loki import send_to_loki + + +def get_size(loki_url: str = None): + cmd = ['restic', 'stats', '--mode', 'raw-data', '--json'] + + result = subprocess.run(cmd, capture_output=True, text=True) + logger.info(result.stdout) + + if loki_url is not None: + send_to_loki(loki_url, result.stdout, backup='size') + + +@click.command() +@click.option('--loki-url', type=str, help='Loki URL for logging', envvar='LOKI_URL') +def main(loki_url: str = None): + get_size(loki_url) + + +if __name__ == '__main__': + main()