From f1ab1ce6d0d2845aa4a4524eee784a08eb3437b8 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Mon, 27 May 2024 12:49:52 -0500 Subject: [PATCH] added disk_size --- src/restic/size.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/restic/size.py b/src/restic/size.py index 5228d4e..1d15a98 100644 --- a/src/restic/size.py +++ b/src/restic/size.py @@ -1,5 +1,6 @@ import json import logging +import os import subprocess import click @@ -18,8 +19,21 @@ def get_size(loki_url: str = None): f'Total size: {data["total_size"] / 10**6:.2f} MB, {data["snapshots_count"]} snapshots' ) + cmd = [ + 'du', + '--summarize', + '--bytes', + '--total', + os.environ['RESTIC_REPOSITORY'], + ] + + result = subprocess.run(cmd, capture_output=True, text=True) + size = int(result.stdout.split()[0]) + data['disk_size'] = size + if loki_url is not None: - send_to_loki(loki_url, result.stdout, backup='size') + send_to_loki(loki_url, json.dumps(data), backup='size') + logger.debug(json.dumps(data, indent=4)) @click.command()