feat add skip cleanup flag and enable success alerts

This commit is contained in:
Michael Reichenbach 2020-11-17 08:34:58 +01:00
parent 8fe4430aa5
commit 5256c14b67
3 changed files with 23 additions and 9 deletions

View file

@ -1,2 +1 @@
10 2 * * * . /env.sh && /backup.sh && rcb cleanup > /proc/1/fd/1 10 2 * * * . /env.sh && /backup.sh && rcb cleanup > /proc/1/fd/1 2>&1

View file

@ -26,6 +26,9 @@ def main():
if args.log_level: if args.log_level:
containers.this_container.set_config_env('LOG_LEVEL', args.log_level) containers.this_container.set_config_env('LOG_LEVEL', args.log_level)
if args.no_cleanup:
config.skip_cleanup = True
if args.action == 'status': if args.action == 'status':
status(config, containers) status(config, containers)
@ -171,6 +174,12 @@ def backup(config, containers):
body=open('backup.log').read(), body=open('backup.log').read(),
alert_type='ERROR', alert_type='ERROR',
) )
else:
alerts.send(
subject="Backup successfully completed",
body=open('backup.log').read(),
alert_type='INFO'
)
def start_backup_process(config, containers): def start_backup_process(config, containers):
@ -241,12 +250,13 @@ def start_backup_process(config, containers):
logger.error('Exit code: %s', errors) logger.error('Exit code: %s', errors)
exit(1) exit(1)
# # Only run cleanup if backup was successful # Only run cleanup if backup was successful
# result = cleanup(config, container) if not config.skip_cleanup:
# logger.debug('cleanup exit code: %s', result) result = cleanup(config, container)
# if result != 0: logger.debug('cleanup exit code: %s', result)
# logger.error('cleanup exit code: %s', result) if result != 0:
# exit(1) logger.error('cleanup exit code: %s', result)
exit(1)
# Test the repository for errors # Test the repository for errors
logger.info("Checking the repository for errors") logger.info("Checking the repository for errors")
@ -319,6 +329,10 @@ def parse_args():
choices=list(log.LOG_LEVELS.keys()), choices=list(log.LOG_LEVELS.keys()),
help="Log level" help="Log level"
) )
parser.add_argument(
'--no-cleanup',
action='store_true'
)
return parser.parse_args() return parser.parse_args()

View file

@ -2,7 +2,7 @@ import os
class Config: class Config:
default_backup_command = ". /env.sh && /backup.sh && rcb cleanup > /proc/1/fd/1" default_backup_command = ". /env.sh && /backup.sh && rcb cleanup > /proc/1/fd/1 2>&1"
default_crontab_schedule = "0 2 * * *" default_crontab_schedule = "0 2 * * *"
"""Bag for config values""" """Bag for config values"""
@ -15,6 +15,7 @@ class Config:
self.swarm_mode = os.environ.get('SWARM_MODE') or False self.swarm_mode = os.environ.get('SWARM_MODE') or False
self.include_project_name = os.environ.get('INCLUDE_PROJECT_NAME') or False self.include_project_name = os.environ.get('INCLUDE_PROJECT_NAME') or False
self.exclude_bind_mounts = os.environ.get('EXCLUDE_BIND_MOUNTS') or False self.exclude_bind_mounts = os.environ.get('EXCLUDE_BIND_MOUNTS') or False
self.skip_cleanup = os.environ.get('SKIP_CLEANUP') or False
# Log # Log
self.log_level = os.environ.get('LOG_LEVEL') self.log_level = os.environ.get('LOG_LEVEL')