more work
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user