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:
@@ -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.
|
||||
|
||||
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user