From 9fda3e62c2f04d63fac1f44ef6960eb48d6fe701 Mon Sep 17 00:00:00 2001
From: David Beniamine <david.beniamine@tetras-libre.fr>
Date: Fri, 25 Jun 2021 09:58:35 +0200
Subject: [PATCH] Remove old increments on fail

---
 backup.sh | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/backup.sh b/backup.sh
index 5998c03..e55feaa 100755
--- a/backup.sh
+++ b/backup.sh
@@ -15,8 +15,18 @@ exit_on_fail(){
 
 retrie_on_fail(){
     if [ $1 -ne 0 ]; then
+        keep=$(($BK_KEEP_FULL-1))
+        if [ $keep -gt 0 ]; then
+            run_duplicity remove-all-inc-of-but-n-full $(($BK_KEEP_FULL-1)) --force
+        else
+            cat <<EOF | lftp $host
+            user $user $ftppass
+
+            rm -rf $remotedir/*-inc*
+            rm -rf $remotedir/*-new-signatures*
+EOF
+        fi
         backup "cleaned"
-        run_duplicity remove-all-inc-of-but-n-full $(($BK_KEEP_FULL-1)) --force
         leave $?
     fi
 }
-- 
GitLab