diff --git a/man/simple_backup.1 b/man/simple_backup.1 index 2c216c7..112455a 100644 --- a/man/simple_backup.1 +++ b/man/simple_backup.1 @@ -98,6 +98,9 @@ if saving bandwith is needed. Remove old backups (if necessary) before creating the new backup. Useful to free some space before performing the backup. Default behavior is to remove old backups after successfully completing the backup. +Note that if the backup fails after old backups have been removed, only the backups kept +according to \-\-keep will be left, and the new backup may be incomplete. In particular, with +\-\-keep 0 there will be no complete backup available until the next successful one. .TP .B \-\-no\-syslog Don't use systemd journal for logging. diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index 8eaf50d..aa5fb67 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -160,6 +160,7 @@ class Backup: self._ssh = None self._password_auth = False self._password = None + self._removed_count = 0 def check_params(self, homedir: str = '') -> int: """Check if parameters for the backup are valid""" @@ -284,6 +285,8 @@ class Backup: logger.error( 'Error while removing backup %s. Permission denied', dirs[i]) + self._removed_count = count + if count == 1: logger.info('Removed %d backup', count) elif count > 1: @@ -602,6 +605,17 @@ class Backup: else: logger.error(output) + if self._removed_count > 0 and returncode not in [0, 24]: + # With --remove-before-backup, old backups are already gone if the new one failed + if self.keep == 0: + message = 'All old backups were removed before the backup, and the new backup may be ' +\ + 'incomplete. No complete backup is available' + else: + message = 'Old backups were removed before the backup, and the new backup may be incomplete' + + logger.error(message) + _notify(message) + if self.keep != -1 and not self._remove_before: # Don't delete old backups if the new one may be incomplete if returncode in [0, 24]: