Last active 6 months ago

Revision 478642ab68f28480826ab60643bbf325a3ad1d2f

xen_vm_sync Raw
1#!/bin/sh
2host=$1; shift;
3vmHost=$1; shift;
4
5# How many Pings send to check the Default Gateway
6PINGCOUNT="5"
7# When should check_icmp gets faulty, see check_icmp --help
8FAULT="5000,100%"
9# Timeout for ping checks
10TIMEOUT="30"
11
12sshPath="/usr/bin/ssh"
13DumpPreUserCmd="$sshPath -q -x -l root ${host} /usr/share/backuppc-helper/lvm_pre_backup ${vmHost}"
14DumpPostUserCmd="$sshPath -q -x -l root ${host} /usr/share/backuppc-helper/lvm_post_backup ${vmHost}"
15
16if [ -f /etc/default/backuppc-helper ]
17then
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
26else
27 echo "#### WARNING ####"
28 echo "/etc/default/backuppc-helper is missing!"
29 echo "#################"
30 exit 0
31fi
32
33if [ `mount | grep ${vmHost} | wc -l` -gt "0" ] ; then
34 echo "#### WARNING ####"
35 echo "/dev/${VOL}/${vmHost}-disk already mounted!"
36 echo "#################"
37 exit 0
38fi
39
40# is the check_icmp binary there?
41if [ ! -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
46fi
47
48# check
49/usr/lib/nagios/plugins/check_icmp -n ${PINGCOUNT} -t ${TIMEOUT} -w ${FAULT} -c ${FAULT} -H ${host} > /dev/null || unreach="true"
50if [ ${unreach} ] ; then
51 echo "#### ERROR ####"
52 echo "$host not reachable!"
53 echo "###############"
54 exit 1
55fi
56
57# create directory
58mkdir -p /mnt/${vmHost}
59
60# mount target fs
61mount /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
67rsync -az --numeric-ids --delete root@${host}:/mnt/${vmHost}/ /mnt/${vmHost}/
68rsync -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
74umount /mnt/${vmHost}