xen_vm_sync
· 2.0 KiB · Text
Sin formato
#!/bin/sh
host=$1; shift;
vmHost=$1; shift;
# How many Pings send to check the Default Gateway
PINGCOUNT="5"
# When should check_icmp gets faulty, see check_icmp --help
FAULT="5000,100%"
# Timeout for ping checks
TIMEOUT="30"
sshPath="/usr/bin/ssh"
DumpPreUserCmd="$sshPath -q -x -l root ${host} /usr/share/backuppc-helper/lvm_pre_backup ${vmHost}"
DumpPostUserCmd="$sshPath -q -x -l root ${host} /usr/share/backuppc-helper/lvm_post_backup ${vmHost}"
if [ -f /etc/default/backuppc-helper ]
then
. /etc/default/backuppc-helper
if [ -z "$VOL" ]
then
echo "#### WARNING ####"
echo "VOL in /etc/default/backuppc-helper not set!"
echo "#################"
exit 0
fi
else
echo "#### WARNING ####"
echo "/etc/default/backuppc-helper is missing!"
echo "#################"
exit 0
fi
if [ `mount | grep ${vmHost} | wc -l` -gt "0" ] ; then
echo "#### WARNING ####"
echo "/dev/${VOL}/${vmHost}-disk already mounted!"
echo "#################"
exit 0
fi
# is the check_icmp binary there?
if [ ! -e /usr/lib/nagios/plugins/check_icmp ]; then
echo "#### ERROR ####"
echo "check_icmp not found! Is nagios-plugins-basic installed?"
echo "###############"
exit 1
fi
# check
/usr/lib/nagios/plugins/check_icmp -n ${PINGCOUNT} -t ${TIMEOUT} -w ${FAULT} -c ${FAULT} -H ${host} > /dev/null || unreach="true"
if [ ${unreach} ] ; then
echo "#### ERROR ####"
echo "$host not reachable!"
echo "###############"
exit 1
fi
# create directory
mkdir -p /mnt/${vmHost}
# mount target fs
mount /dev/${VOL}/${vmHost}-disk /mnt/${vmHost}
# mount snapshot of source fs on remote system
$DumpPreUserCmd
# sync remote filesystem with local once
rsync -az --numeric-ids --delete root@${host}:/mnt/${vmHost}/ /mnt/${vmHost}/
rsync -az --numeric-ids --delete root@${host}:/etc/xen/${vmHost}* /etc/xen/
# umount snapshot of source fs on remote system
$DumpPostUserCmd
# umount target fs
umount /mnt/${vmHost}
| 1 | #!/bin/sh |
| 2 | host=$1; shift; |
| 3 | vmHost=$1; shift; |
| 4 | |
| 5 | # How many Pings send to check the Default Gateway |
| 6 | PINGCOUNT="5" |
| 7 | # When should check_icmp gets faulty, see check_icmp --help |
| 8 | FAULT="5000,100%" |
| 9 | # Timeout for ping checks |
| 10 | TIMEOUT="30" |
| 11 | |
| 12 | sshPath="/usr/bin/ssh" |
| 13 | DumpPreUserCmd="$sshPath -q -x -l root ${host} /usr/share/backuppc-helper/lvm_pre_backup ${vmHost}" |
| 14 | DumpPostUserCmd="$sshPath -q -x -l root ${host} /usr/share/backuppc-helper/lvm_post_backup ${vmHost}" |
| 15 | |
| 16 | if [ -f /etc/default/backuppc-helper ] |
| 17 | then |
| 18 | . /etc/default/backuppc-helper |
| 19 | if [ -z "$VOL" ] |
| 20 | then |
| 21 | echo "#### WARNING ####" |
| 22 | echo "VOL in /etc/default/backuppc-helper not set!" |
| 23 | echo "#################" |
| 24 | exit 0 |
| 25 | fi |
| 26 | else |
| 27 | echo "#### WARNING ####" |
| 28 | echo "/etc/default/backuppc-helper is missing!" |
| 29 | echo "#################" |
| 30 | exit 0 |
| 31 | fi |
| 32 | |
| 33 | if [ `mount | grep ${vmHost} | wc -l` -gt "0" ] ; then |
| 34 | echo "#### WARNING ####" |
| 35 | echo "/dev/${VOL}/${vmHost}-disk already mounted!" |
| 36 | echo "#################" |
| 37 | exit 0 |
| 38 | fi |
| 39 | |
| 40 | # is the check_icmp binary there? |
| 41 | if [ ! -e /usr/lib/nagios/plugins/check_icmp ]; then |
| 42 | echo "#### ERROR ####" |
| 43 | echo "check_icmp not found! Is nagios-plugins-basic installed?" |
| 44 | echo "###############" |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | # check |
| 49 | /usr/lib/nagios/plugins/check_icmp -n ${PINGCOUNT} -t ${TIMEOUT} -w ${FAULT} -c ${FAULT} -H ${host} > /dev/null || unreach="true" |
| 50 | if [ ${unreach} ] ; then |
| 51 | echo "#### ERROR ####" |
| 52 | echo "$host not reachable!" |
| 53 | echo "###############" |
| 54 | exit 1 |
| 55 | fi |
| 56 | |
| 57 | # create directory |
| 58 | mkdir -p /mnt/${vmHost} |
| 59 | |
| 60 | # mount target fs |
| 61 | mount /dev/${VOL}/${vmHost}-disk /mnt/${vmHost} |
| 62 | |
| 63 | # mount snapshot of source fs on remote system |
| 64 | $DumpPreUserCmd |
| 65 | |
| 66 | # sync remote filesystem with local once |
| 67 | rsync -az --numeric-ids --delete root@${host}:/mnt/${vmHost}/ /mnt/${vmHost}/ |
| 68 | rsync -az --numeric-ids --delete root@${host}:/etc/xen/${vmHost}* /etc/xen/ |
| 69 | |
| 70 | # umount snapshot of source fs on remote system |
| 71 | $DumpPostUserCmd |
| 72 | |
| 73 | # umount target fs |
| 74 | umount /mnt/${vmHost} |