added prune module
This commit is contained in:
33
src/restic/prune.py
Normal file
33
src/restic/prune.py
Normal 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()
|
||||||
Reference in New Issue
Block a user