#!/bin/bash
. /etc/systemconfig
BACKUPDIR=/data/storage/disk0/backup/system_backups


#find last backup
cd $BACKUPDIR
restore_file=`ls -t backup.*|head -1`
cd -

if [ $SystemType != Master_backend -a  $SystemType != Standalone ]
then
    msg_client.py --msg "This is not the Master backend.\n Skipping restore of database."
fi

#do the backup
msg_client.py --msg "Restoring from:\n$restore_file"
lh_system_restore_job $restore_file 2>&1 > /var/run/restore.log
rc=$?

if [ $rc = 0 ]
then
    complete_message="Restore completed successfully"
else
    complete_message="Restore failed!"
fi

msg_client.py --msg "$complete_message"



#don't try to restore DB if not master
