Newer
Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2017, Florent Thiery
'''
Criticality: Medium
Checks that the server backups are not older than a day
'''
import os
import sys
import subprocess
import imp
from datetime import datetime
os.chdir(os.path.dirname(__file__))
def test_ssh(server):
status, out = subprocess.getstatusoutput('ssh %s ls /tmp' % server)
return status == 0
def test_last_backup_is_recent(server, client):
path = '/backup/%s/current' % client
cmd = 'ssh %s ls -l %s | grep current' % (server, path)
date = out.strip().split(' ')[-2]
pdate = datetime.strptime(date, '%Y-%m-%d')
print('Backup is older than 2 days')
return False
else:
return True
else:
return False
if os.path.isfile('../utils.py'):
es_utils = imp.load_source('es_utils', '../utils.py')
conf = es_utils.load_conf()
BURP_SERVER = conf.get('BURP_SERVER')
BURP_CLIENT_NAME = conf.get('BURP_CLIENT_NAME', 'localhost')
if BURP_SERVER:
if not test_ssh(BURP_SERVER):
print('Failed to ssh into backup server')
sys.exit(1)
else:
test_last_backup_is_recent(BURP_SERVER, BURP_CLIENT_NAME)
else:
sys.exit(2)
else:
sys.exit(2)