diff --git a/src/crontab b/src/crontab index 20da2cd..ec4a0f7 100644 --- a/src/crontab +++ b/src/crontab @@ -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 \ No newline at end of file diff --git a/src/restic_compose_backup/cli.py b/src/restic_compose_backup/cli.py index 317178e..d39a5c8 100644 --- a/src/restic_compose_backup/cli.py +++ b/src/restic_compose_backup/cli.py @@ -26,6 +26,9 @@ def main(): if 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': status(config, containers) @@ -171,6 +174,12 @@ def backup(config, containers): body=open('backup.log').read(), alert_type='ERROR', ) + else: + alerts.send( + subject="Backup successfully completed", + body=open('backup.log').read(), + alert_type='INFO' + ) def start_backup_process(config, containers): @@ -241,12 +250,13 @@ def start_backup_process(config, containers): logger.error('Exit code: %s', errors) exit(1) - # # Only run cleanup if backup was successful - # result = cleanup(config, container) - # logger.debug('cleanup exit code: %s', result) - # if result != 0: - # logger.error('cleanup exit code: %s', result) - # exit(1) + # Only run cleanup if backup was successful + if not config.skip_cleanup: + result = cleanup(config, container) + logger.debug('cleanup exit code: %s', result) + if result != 0: + logger.error('cleanup exit code: %s', result) + exit(1) # Test the repository for errors logger.info("Checking the repository for errors") @@ -319,6 +329,10 @@ def parse_args(): choices=list(log.LOG_LEVELS.keys()), help="Log level" ) + parser.add_argument( + '--no-cleanup', + action='store_true' + ) return parser.parse_args() diff --git a/src/restic_compose_backup/config.py b/src/restic_compose_backup/config.py index 749e84a..59568e9 100644 --- a/src/restic_compose_backup/config.py +++ b/src/restic_compose_backup/config.py @@ -2,7 +2,7 @@ import os 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 * * *" """Bag for config values""" @@ -15,6 +15,7 @@ class Config: self.swarm_mode = os.environ.get('SWARM_MODE') 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.skip_cleanup = os.environ.get('SKIP_CLEANUP') or False # Log self.log_level = os.environ.get('LOG_LEVEL')