#!/bin/bash ######################################### XENDIR=/opt/xen XENUS="xenmail xenldap xenldns xenadm xenfw xenweb" VOLUME=vg00 MAILTO=backup@localhost DATE=`date +%Y%m%d` DOMNAME=`uname -n` BACKUPDIR=/var/${DOMNAME}backup LOGDIR=/var/log/${DOMNAME}backup LOGFILE=${LOGDIR}/${DOMNAME}backup.log-${DATE} ######################################### function infoevent { echo "`date +%c` INFO $1" >> ${LOGFILE} } function warnevent { echo " `date +%c` WARNING $1" >> ${LOGFILE} echo "$1 on ${DATE}" | /usr/bin/mailx -s "$1" ${MAILTO} } cd ${XENDIR} # Test and create backupdir and logdir /usr/bin/test -d ${BACKUPDIR} || mkdir -p ${BACKUPDIR} /usr/bin/test -d ${LOGDIR} || mkdir -p ${LOGDIR} # Clean up backup directory and old logfiles rm -f ${BACKUPDIR}/* find ${LOGDIR} -ctime +30 -exec rm -f {} \; # Backup other xen guests for XENHOST in ${XENUS}; do DOMAINVOL=/dev/${VOLUME}/${XENHOST} SIZE=`/sbin/lvs -o lv_size --noheadings ${DOMAINVOL}` infoevent "Start backup ${XENHOST}..." /usr/sbin/xm save ${XENHOST} ${BACKUPDIR}/${XENHOST}.saved infoevent "${XENHOST} saved..." /sbin/lvcreate -L ${SIZE} -s -n ${XENHOST}snapshot ${DOMAINVOL} /usr/sbin/xm restore ${BACKUPDIR}/${XENHOST}.saved infoevent "${XENHOST} restored..." cat ${BACKUPDIR}/${XENHOST}.saved | gzip > ${BACKUPDIR}/${XENHOST}-saved-${DATE}.gz rm -f ${BACKUPDIR}/${XENHOST}.saved infoevent "Backup file ${XENHOST}.saved completed..." dd if=${DOMAINVOL}snapshot| gzip > ${BACKUPDIR}/${XENHOST}-${DATE}.dd.gz infoevent "Backup image snapshot ${XENHOST} completed" /sbin/lvremove -f ${DOMAINVOL}snapshot infoevent "Temporary snapshot ${XENHOST} removed" infoevent "Backup ${XENHOST} completed..." done # Other dirs 2 backup tar -zcvf ${BACKUPDIR}/${DOMNAME}-etc-${DATE}.tar.gz /etc tar -zcvf ${BACKUPDIR}/${DOMNAME}-varldap-${DATE}.tar.gz /var/ldap tar -zcvf ${BACKUPDIR}/${DOMNAME}-optxen-${DATE}.tar.gz /opt/xen infoevent "Backup other directories created..." # Daily backup 2 tape if mt -f /dev/st0 status | grep ONLINE then infoevent "Start backup to tape..." tar -cvf /dev/st0 ${BACKUPDIR}/* infoevent "Backup to tape completed..." else warnevent "Tape ${DOMNAME} NOT inserted!" fi