Catch exceptions in backup_runner

This commit is contained in:
Einar Forselv 2019-12-05 10:16:34 +01:00
parent c59f022a55
commit 0af9f2e8ee
1 changed files with 23 additions and 13 deletions

View File

@ -89,17 +89,27 @@ def backup(config, containers):
mounts = containers.generate_backup_mounts('/volumes') mounts = containers.generate_backup_mounts('/volumes')
volumes.update(mounts) volumes.update(mounts)
result = backup_runner.run( try:
image=containers.this_container.image, result = backup_runner.run(
command='restic-compose-backup start-backup-process', image=containers.this_container.image,
volumes=volumes, command='restic-compose-backup start-backup-process',
environment=containers.this_container.environment, volumes=volumes,
source_container_id=containers.this_container.id, environment=containers.this_container.environment,
labels={ source_container_id=containers.this_container.id,
"restic-compose-backup.backup_process": 'True', labels={
"com.docker.compose.project": containers.project_name, "restic-compose-backup.backup_process": 'True',
}, "com.docker.compose.project": containers.project_name,
) },
)
except Exception as ex:
logger.exception(ex)
alerts.send(
subject="Exception during backup",
body=str(ex),
alert_type='ERROR',
)
return
logger.info('Backup container exit code: %s', result) logger.info('Backup container exit code: %s', result)
# Alert the user if something went wrong # Alert the user if something went wrong
@ -133,7 +143,7 @@ def start_backup_process(config, containers):
logger.error('Backup command exited with non-zero code: %s', vol_result) logger.error('Backup command exited with non-zero code: %s', vol_result)
errors = True errors = True
except Exception as ex: except Exception as ex:
logger.error(ex) logger.exception(ex)
errors = True errors = True
# back up databases # back up databases
@ -148,7 +158,7 @@ def start_backup_process(config, containers):
logger.error('Backup command exited with non-zero code: %s', result) logger.error('Backup command exited with non-zero code: %s', result)
errors = True errors = True
except Exception as ex: except Exception as ex:
logger.error(ex) logger.exception(ex)
errors = True errors = True
if errors: if errors: