Browse Source

Update backup-volumes.py

master
Sean Johnson 2 years ago
parent
commit
8a40d19a97
  1. 26
      resource/tools/backup-volumes.py

26
resource/tools/backup-volumes.py

@ -11,7 +11,7 @@ import shutil
import sys
import traceback
from datetime import datetime
from typing import Iterator, List, Optional, Sequence, Union
from typing import Iterator, List, Optional, Sequence, T, Type, Union
_CONVOY_DATE_FMT = "%a %b %d %H:%M:%S %z %Y"
BACKUP_DESTINATION = os.getenv("BACKUP_DESTINATION", None)
@ -83,6 +83,16 @@ def chunked_iter(items: Sequence, size: int) -> Iterator[List[List]]:
yield items[index : index + size]
def excepthook(etype: Type[T], value: T, traceback: "traceback object"):
context = {
"exc_class": type.__name__,
"exc_text": "".join(traceback.format_exception_only(etype, value)),
"traceback": "".join(traceback.format_exception(etype, value, traceback)),
}
log_stdout(MSG_ERROR, **context)
def log_stdout(message, exception: Optional[Exception] = None, **context):
message = {
"timestamp": timestamp_log(),
@ -119,9 +129,15 @@ async def get_proc_response(
stdout, _ = await proc.communicate()
if proc.returncode != 0:
if onfail_msg is not None:
log_stdout(
onfail_msg, return_code=proc.returncode, stdout=stdout.decode("utf-8")
)
try:
stdout = stdout.decode("utf-8")
stdout = json.loads(stdout)
log_stdout(
onfail_msg, return_code=proc.returncode, stdout=stdout,
)
except Exception as err:
pass
raise RuntimeError(
f"Convoy is not okay: return code {proc.returncode}: {stdout}"
@ -299,6 +315,8 @@ async def clean_older_snapshots(vol_data: dict):
async def main():
sys.excepthook = excepthook
log_stdout(MSG_STARTING)
while True:
try:

Loading…
Cancel
Save