Warn if a backup fails after old backups were removed

With --remove-before-backup, a failed backup leaves only the kept
backups, or none with keep=0. Log an error and send a notification
in that case, and document it in the man page.
This commit is contained in:
Fuxino
2026-10-08 18:13:13 +02:00
parent 30e4416f8f
commit 871dd0f49a
2 changed files with 17 additions and 0 deletions
+14
View File
@@ -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]: