Skip to content
Snippets Groups Projects
Commit a43c57f6 authored by Florent Thiery's avatar Florent Thiery
Browse files

add check to verify that backup is incremental refs #23246

parent 574c91ae
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ import os
import socket
import subprocess
import sys
import glob
GREEN = '\033[92m'
RED = '\033[91m'
......@@ -19,12 +19,15 @@ DEF = '\033[0m'
MAX_AGE_H = 48
def print_red(string):
print(RED + string + DEF)
def print_green(string):
print(GREEN + string + DEF)
def test_ssh(ip):
cmd = 'ssh -o StrictHostKeyChecking=no -o PasswordAuthentication=no %s ls /tmp' % ip
print('Connecting to MediaVault: %s' % cmd)
......@@ -64,7 +67,7 @@ def test_backup_space(server=None, path="/backup"):
status, out = subprocess.getstatusoutput(cmd)
if status == 0:
dev, total, used, free, used_perc, mount = out.strip().split()
used_perc = int(used_perc.replace('%',''))
used_perc = int(used_perc.replace('%', ''))
if used_perc > 80:
print('There is less than 20% of available space for backups')
return False
......@@ -75,6 +78,24 @@ def test_backup_space(server=None, path="/backup"):
print('Failed to check backup space')
return False
def check_backup_is_incremental(path):
dirs = os.listdir(path)
dirs.sort()
for d in dirs:
num_folders = 0
if os.path.isdir(d):
media = glob.glob(os.path.join(path, d, "*/msinstance/media/resources/"))
for m in media:
num_folders += len(os.listdir(m))
print('%s: %s' % (d, num_folders))
if num_folders == 0:
print('Folder %s is empty, this indicates non-incremental backups (we are expecting links)' % d)
return False
return True
def check_local_backup(path):
all_ok = True
backup_folder = os.path.dirname(path)
......@@ -87,11 +108,13 @@ def check_local_backup(path):
d = datetime.strptime(date, '%Y-%m-%d-%H%M%S')
now = datetime.now()
diff_seconds = (now - d).total_seconds()
if diff_seconds > MAX_AGE_H*3600:
print_red('Backup %s is older than %sh (%ih)' % (backup_folder, MAX_AGE_H, diff_seconds/3600))
all_ok = False
if diff_seconds > MAX_AGE_H * 3600:
print_red('Backup %s is older than %sh (%ih)' % (backup_folder, MAX_AGE_H, diff_seconds / 3600))
all_ok = False
else:
print_green('Backup %s is fine' % backup_folder)
if not check_backup_is_incremental(backup_folder):
all_ok = False
elif os.path.exists(os.path.join(backup_folder, 'backup.inprogress')):
print_red('Initial backup %s still running' % backup_folder)
all_ok = False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment