diff --git a/src/restic/prune.py b/src/restic/prune.py new file mode 100644 index 0000000..3d9128e --- /dev/null +++ b/src/restic/prune.py @@ -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()