From 1905e3b76860f580890195f7743a67ddeaa21d9a 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:13:18 +0200 Subject: [PATCH] support local folder for backups checking, refs #21677 --- global-conf.sh | 4 +++- tests/test_backup.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/global-conf.sh b/global-conf.sh index 0a250a06..fbdf32b9 100644 --- a/global-conf.sh +++ b/global-conf.sh @@ -108,8 +108,10 @@ BURP_MAIL_DEST='sysadmin@ubicast.eu' BURP_CLIENT_NAME= BURP_CLIENT_MAIL_DEST='sysadmin@ubicast.eu' -# -- tmbackup +# -- tmbackup.sh -- BACKUP_SERVER='' +# CSV separated +LOCAL_BACKUP_FOLDERS='/backup' # -- FTP -- # move uploaded files into hotfolder diff --git a/tests/test_backup.py b/tests/test_backup.py index d26d11bf..1ab42e25 100755 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -67,11 +67,42 @@ def test_backup_space(server): return False +def check_local_backup(path): + for d in os.listdir(path): + subd = os.path.join(path, d) + latest = os.path.join(subd, 'latest') + if os.exists(latest): + mtime = os.path.getmtime(latest) + d = datetime.fromtimestamp(mtime) + now = datetime.now() + diff_seconds = (now - d).total_seconds() + if diff_seconds > 25*3600: + print('Backup %s is older than a day' % subd) + return False + else: + print('Backup %s is fine' % subd) + return True + else: + print('Backup %s is not okay (no %s file)' % (subd, latest)) + return False + + +def check_local_backups(paths): + all_ok = True + blacklist = ('lost+found') + folders = paths.split(',') + for f in folders: + if f not in blacklist: + all_ok = min(check_local_backup(f), all_ok) + return all_ok + + os.chdir(os.path.dirname(__file__)) if os.path.isfile('../utils.py'): es_utils = imp.load_source('es_utils', '../utils.py') conf = es_utils.load_conf() BACKUP_SERVER = conf.get('BACKUP_SERVER') + LOCAL_BACKUP_FOLDERS = conf.get('LOCAL_BACKUP_FOLDERS') if BACKUP_SERVER: if not test_ssh(BACKUP_SERVER): print('Failed to ssh into backup server') @@ -84,6 +115,8 @@ if os.path.isfile('../utils.py'): sys.exit(1) else: sys.exit(0) + elif LOCAL_BACKUP_FOLDERS: + sys.exit(check_local_backups(LOCAL_BACKUP_FOLDERS)) else: print('No BACKUP_SERVER defined in config, untestable') sys.exit(2) -- GitLab