added prune module

This commit is contained in:
John Lancaster
2024-05-25 22:22:06 -05:00
parent fb95a111e4
commit b05b361dd4

33
src/restic/prune.py Normal file
View File

@@ -0,0 +1,33 @@
import logging
import re
import subprocess
from restic.console import console, logger
def main(dry_run: bool = False):
cmd = ['restic', 'prune']
if dry_run:
cmd.append('-n')
logger.debug(f'Running cmd [bright_black]{" ".join(cmd)}[/]')
with console.status('Pruning...'):
result = subprocess.run(cmd, capture_output=True, text=True)
if m := re.search(r'total prune:\s+(.*?)$', result.stdout, re.MULTILINE):
pruned_data = m.group(1).split(' / ')[1]
logger.info(f'Pruned {pruned_data}')
if m := re.search(r'remaining:\s+(.*?)$', result.stdout, re.MULTILINE):
remaining = m.group(1).split(' / ')[1]
logger.info(f'{remaining} remaining')
if __name__ == '__main__':
from rich.logging import RichHandler
logging.basicConfig(
level='DEBUG', format='%(message)s', handlers=[RichHandler(markup=True, console=console)]
)
main()