added size module
This commit is contained in:
@@ -8,7 +8,7 @@ from rich.console import Console
|
|||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
from rich.progress import Progress
|
from rich.progress import Progress
|
||||||
|
|
||||||
from restic import snapshots
|
from restic import size, snapshots
|
||||||
from restic.console import console, logger
|
from restic.console import console, logger
|
||||||
from restic.docker import manage_containers
|
from restic.docker import manage_containers
|
||||||
from restic.loki import send_to_loki
|
from restic.loki import send_to_loki
|
||||||
@@ -92,6 +92,7 @@ def main(
|
|||||||
console.print_exception()
|
console.print_exception()
|
||||||
else:
|
else:
|
||||||
snapshots.run(loki_url)
|
snapshots.run(loki_url)
|
||||||
|
size.get_size(loki_url)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
26
src/restic/size.py
Normal file
26
src/restic/size.py
Normal 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()
|
||||||
Reference in New Issue
Block a user