fleshed out prune module

This commit is contained in:
John Lancaster
2024-05-27 19:20:47 -05:00
parent 33260592f5
commit 9127b34739
2 changed files with 44 additions and 14 deletions

View File

@@ -4,8 +4,10 @@ import re
import subprocess
import sys
import click
from rich.logging import RichHandler
from restic import size, snapshots
from restic.console import console, logger
from restic.loki import send_to_loki
@@ -52,12 +54,27 @@ def prune(loki_url: str = None, dry_run: bool = False):
send_to_loki(loki_url, line=json.dumps(d), backup='prune')
def main():
@click.command()
@click.option(
'--loki-url',
type=str,
help='Loki URL for logging. Defaults to the LOKI_URL env variable',
envvar='LOKI_URL',
default=None,
)
@click.option('-n', '--dry-run', type=bool, default=False, is_flag=True)
def main(loki_url: str, dry_run: bool):
logging.basicConfig(
level='DEBUG', format='%(message)s', handlers=[RichHandler(markup=True, console=console)]
)
prune(dry_run=True)
try:
prune(loki_url=loki_url, dry_run=dry_run)
except Exception as e:
raise e
else:
snapshots.snapshot(loki_url)
size.get_size(loki_url)
if __name__ == '__main__':