added size module

This commit is contained in:
John Lancaster
2024-05-27 01:23:17 -05:00
parent be7b64f8e4
commit 9248162bf7
2 changed files with 28 additions and 1 deletions

View File

@@ -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__':

26
src/restic/size.py Normal file
View File

@@ -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()