From 65fedeb61802a17f1273dfd9ce10ee9d43fc5c4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu>
Date: Thu, 1 Jun 2017 11:56:29 +0200
Subject: [PATCH] parse folder name instead of modification time which is
 preserved by rsync, fix return code, fixes #21677

---
 tests/test_backup.py | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tests/test_backup.py b/tests/test_backup.py
index 75404d39..cfea1332 100755
--- a/tests/test_backup.py
+++ b/tests/test_backup.py
@@ -78,12 +78,14 @@ def check_local_backup(path):
     print('Checking %s' % backup_folder)
     latest = os.path.join(backup_folder, 'latest')
     if os.path.exists(latest):
-        mtime = os.path.getmtime(latest)
-        d = datetime.fromtimestamp(mtime)
+        # resolve symbolic link
+        latest = os.path.realpath(latest)
+        date = os.path.basename(latest)
+        d = datetime.strptime(date, '%Y-%m-%d-%H%M%S')
         now = datetime.now()
         diff_seconds = (now - d).total_seconds()
-        if diff_seconds > 48*3600:
-            print_red('Backup %s is older than 48h (%ih)' % (backup_folder, diff_seconds/3600))
+        if diff_seconds > 24*3600:
+            print_red('Backup %s is older than 24h (%ih)' % (backup_folder, diff_seconds/3600))
             all_ok = False 
         else:
             print_green('Backup %s is fine' % backup_folder)
@@ -126,7 +128,7 @@ if os.path.isfile('../utils.py'):
                 else:
                     sys.exit(0)
     elif LOCAL_BACKUP_FOLDERS:
-        sys.exit(check_local_backups(LOCAL_BACKUP_FOLDERS))
+        sys.exit(not check_local_backups(LOCAL_BACKUP_FOLDERS))
     else:
         print('No BACKUP_SERVER defined in config, untestable')
         sys.exit(2)
-- 
GitLab