Compare commits
3 Commits
a540f4336f
...
81d430b56b
Author | SHA1 | Date | |
---|---|---|---|
81d430b56b | |||
2d89e530be | |||
3024cf2e69 |
24
backup.py
24
backup.py
|
@ -15,6 +15,7 @@ import select
|
|||
import pathlib
|
||||
import threading
|
||||
import subprocess
|
||||
import _thread # for interrupt_main
|
||||
|
||||
import typing
|
||||
|
||||
|
@ -317,10 +318,7 @@ def main(argv: typing.List[str]):
|
|||
for line in fh:
|
||||
try:
|
||||
data = json.loads(line)
|
||||
if ((data['type'] == 'log_message' or
|
||||
data['type'] == 'progress_message')
|
||||
and 'message' in data):
|
||||
|
||||
if data['type'] == 'log_message':
|
||||
# Count warnings and errors, but ignore some.
|
||||
changed_msg = "file changed while we backed it up"
|
||||
if data['levelname'] == 'WARNING':
|
||||
|
@ -334,6 +332,11 @@ def main(argv: typing.List[str]):
|
|||
prefix = ""
|
||||
|
||||
line = (prefix + data['message'] + '\n').encode()
|
||||
|
||||
elif (data['type'] == 'progress_message'
|
||||
and 'message' in data):
|
||||
line = (data['message'] + '\n').encode()
|
||||
|
||||
elif data['type'] == 'archive_progress':
|
||||
now = time.time()
|
||||
if now - last_progress > 10:
|
||||
|
@ -353,13 +356,20 @@ def main(argv: typing.List[str]):
|
|||
# ignore unknown progress line
|
||||
continue
|
||||
except Exception as e:
|
||||
# on error, print raw line
|
||||
pass
|
||||
# on error, print raw line with exception
|
||||
line = f"[exception: {str(e)} ]".encode() + line
|
||||
sys.stdout.buffer.write(line)
|
||||
sys.stdout.flush()
|
||||
captured_output.append(line)
|
||||
fh.close()
|
||||
reader = threading.Thread(target=reader_thread, args=(borg.stdout,))
|
||||
def _reader_thread(fh):
|
||||
try:
|
||||
return reader_thread(fh)
|
||||
except BrokenPipeError:
|
||||
pass
|
||||
except Exception:
|
||||
_thread.interrupt_main()
|
||||
reader = threading.Thread(target=_reader_thread, args=(borg.stdout,))
|
||||
reader.daemon = True
|
||||
reader.start()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user