File: //lib/python2.7/site-packages/lap/postgresql_physical_backup.py
import datetime
import os
import os.path
from ConfigParser import ConfigParser
from glob import glob
# deprecated. Use barman instead
# check postgresql backup.
# this script expects the package backup-postgresql >= 2.0
# since in the end of backup postgresql archives a *backup*,
# we can use it to monitor the backup
def __run__(params):
min_age = int(params.get('min_backup_age'))
min_date = datetime.datetime.now() - datetime.timedelta(hours=min_age)
cp = ConfigParser()
conf_file = "/etc/dbas/postgresql/backup.conf"
cp.read(conf_file)
archive_path = cp.get('backup_physical', 'backup_archive')
for f in glob(os.path.join(archive_path, '*backup*')):
s = os.stat(f)
f_date = datetime.datetime.fromtimestamp(s.st_ctime)
if f_date >= min_date:
return [0, 'OK: Last backup {0}'.format(f_date)]
return [2, 'CRITICAL: no recent backup found']