Sunday, 16 August 2015

Ovirt Manager Backup Script


#!/bin/bash
today=`date +"%d-%B-%Y"`
remove_3day_old_file=`date +"%d-%B-%Y" --date="3 day ago"`
(
if [ -d /usr/local/ovirt_backup ]
then
echo "Backup Folder /usr/local/ovirt_backup exist"
else
mkdir /usr/local/ovirt_backup
fi
echo "Backup Started `date`"
/usr/bin/engine-backup --mode=backup --scope=all --file=/usr/local/ovirt_backup/ovirt_backup_`date +%d-%B-%Y`.tar --log=/usr/local/ovirt_backup/ovirt_backup_`date +%d-%B-%Y`_log.txt
scp /usr/local/ovirt_backup/ovirt_backup_`date +%d-%B-%Y`* scpuser@destination.example.com:/data/Server_Backups/ovirtmanager/
#rm /usr/local/ovirt_backup/ovirt_backup_$remove_3day_old_file* -f
echo "rm /usr/local/ovirt_backup/ovirt_backup_$remove_3day_old_file* -f"
echo "Backup Completed `date`"

)1>/tmp/ovirtmanager_bkp_out.txt 2>/tmp/ovirtmanager_bkp_err.txt

if [ -s /tmp/ovirtmanager_bkp_err.txt ]
then
(
        echo "To: mdmansoor26@gmail.com"
        echo "From: mdmansoor26@gmail.com"
        echo "Subject: [Alert] $0 script Error `hostname`"
        echo -e "Dear Team,\n\n"
        echo -e "\n\nContents of /tmp/ovirtmanager_bkp_err.txt"
        cat /tmp/ovirtmanager_bkp_err.txt
        echo -e "\n\nRegards,\nLinux Admin Team\n\n"
        echo -e "\n*** THIS IS A AUTO GENERATED ALERT GENERATED AT `date` ***\n"
)| /usr/sbin/sendmail -t -f mdmansoor26@gmail.com

else

(
        echo "To: mdmansoor26@gmail.com"
        echo "From: mdmansoor26@gmail.com"
        echo "Subject: [INFO] Ovirtmanager Backup completed on `date +"%d-%B-%Y"`"
        echo -e "Dear Team,"
        echo -e "\n\nOvirtmanager Backup completed on `date +"%d-%B-%Y"`"
        echo -e "\n\nScript Running in host: `hostname`"
        echo -e "\n\nScript Name: $0"
        echo -e "\n\nSource Path: ovirtmanager:/usr/local/ovirt_backup/ovirt_backup_`date +"%d-%B-%Y"`.tar & /usr/local/ovirt_backup/ovirt_backup_`date +"%d-%B-%Y"`_log.txt"
        echo -e "\n\nDestination Path: destination.example.com:/data/Server_Backups/ovirtmanager/ovirt_backup_`date +"%d-%B-%Y"`.tar & ovirt_backup_`date +"%d-%B-%Y"`_log.txt"
        echo -e "\n\nRegards,\nProd Support Team\n\n"
        echo -e "\n*** THIS IS A AUTO GENERATED ALERT GENERATED AT `date` ***\n"
)| /usr/sbin/sendmail -t -f mdmansoor26@gmail.com

fi
[root@ovirtmanager ovirt_backup]#

1 comment: