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
+3
View File
@@ -98,6 +98,9 @@ if saving bandwith is needed.
Remove old backups (if necessary) before creating the new backup. Useful to free some space Remove old backups (if necessary) before creating the new backup. Useful to free some space
before performing the backup. before performing the backup.
Default behavior is to remove old backups after successfully completing 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 .TP
.B \-\-no\-syslog .B \-\-no\-syslog
Don't use systemd journal for logging. Don't use systemd journal for logging.
+14
View File
@@ -160,6 +160,7 @@ class Backup:
self._ssh = None self._ssh = None
self._password_auth = False self._password_auth = False
self._password = None self._password = None
self._removed_count = 0
def check_params(self, homedir: str = '') -> int: def check_params(self, homedir: str = '') -> int:
"""Check if parameters for the backup are valid""" """Check if parameters for the backup are valid"""
@@ -284,6 +285,8 @@ class Backup:
logger.error( logger.error(
'Error while removing backup %s. Permission denied', dirs[i]) 'Error while removing backup %s. Permission denied', dirs[i])
self._removed_count = count
if count == 1: if count == 1:
logger.info('Removed %d backup', count) logger.info('Removed %d backup', count)
elif count > 1: elif count > 1:
@@ -602,6 +605,17 @@ class Backup:
else: else:
logger.error(output) 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: if self.keep != -1 and not self._remove_before:
# Don't delete old backups if the new one may be incomplete # Don't delete old backups if the new one may be incomplete
if returncode in [0, 24]: if returncode in [0, 24]: