From 871dd0f49a9c61ff45aff6086ac4e7b4c6adb3d2 Mon Sep 17 00:00:00 2001 From: Fuxino Date: Thu, 8 Oct 2026 18:13:13 +0200 Subject: [PATCH] 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. --- man/simple_backup.1 | 3 +++ simple_backup/simple_backup.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) 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]: