more work

This commit is contained in:
John Lancaster
2024-05-27 00:08:38 -05:00
parent 6a546c92ec
commit 17f9fa203e
5 changed files with 33 additions and 19 deletions

View File

@@ -10,21 +10,15 @@ from restic.loki import send_to_loki
def run(loki_url: str = None):
cmd = 'restic snapshots --json'
cmd = ['restic', 'snapshots', '--json']
logger.debug(f'Running cmd [bright_black]{cmd}[/]')
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True
)
with console.status('Getting snapshots...'):
logger.debug(f'Running cmd [bright_black]{" ".join(cmd)}[/]')
result = subprocess.run(cmd, capture_output=True, text=True)
with process.stdout:
for line in iter(process.stdout.readline, ''):
try:
data = json.loads(line)
except Exception as e:
logger.exception(e)
else:
console.print(data)
line = result.stdout
data = json.loads(line)
console.print(data)
if loki_url is not None:
send_to_loki(loki_url=loki_url, line=line, backup='snapshots')