sync_bare2xen.sh
· 2.5 KiB · Bash
Raw
#!/bin/bash
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 ${1} | wc -l` -gt "0" ] ; then
echo "#### WARNING ####"
echo "/dev/${VOL}/${1}-disk already mounted!"
echo "#################"
exit 0
fi
mkdir -p /mnt/${1}
mount /dev/${VOL}/${1}-disk /mnt/${1}
rsync -avz --numeric-ids --delete root@${1}:/bin/ /mnt/${1}/bin/
rsync -avz --numeric-ids --delete root@${1}:/dev/ /mnt/${1}/dev/
rsync -avz --numeric-ids --delete --exclude=inittab --exclude=network/interfaces --exclude=fstab root@${1}:/etc/ /mnt/${1}/etc/
rsync -avz --numeric-ids --delete root@${1}:/home/ /mnt/${1}/home/
rsync -avz --numeric-ids --delete root@${1}:/initrd/ /mnt/${1}/initrd/
rsync -avz --numeric-ids --delete root@${1}:/lib32/ /mnt/${1}/lib32/
rsync -avz --numeric-ids --delete root@${1}:/lib/ /mnt/${1}/lib/
rsync -avz --numeric-ids --delete root@${1}:/lib64 /mnt/${1}/lib64
rsync -avz --numeric-ids --delete root@${1}:/media/ /mnt/${1}/media/
rsync -avz --numeric-ids --delete root@${1}:/mnt/ /mnt/${1}/mnt/
rsync -avz --numeric-ids --delete root@${1}:/opt/ /mnt/${1}/opt/
rsync -avz --numeric-ids --delete root@${1}:/root/ /mnt/${1}/root/
rsync -avz --numeric-ids --delete root@${1}:/sbin/ /mnt/${1}/sbin/
rsync -avz --numeric-ids --delete root@${1}:/srv/ /mnt/${1}/srv/
#rsync -avz --numeric-ids --delete root@${1}:/sys/ /mnt/${1}/sys/
rsync -avz --numeric-ids --delete root@${1}:/tmp/ /mnt/${1}/tmp/
rsync -avz --numeric-ids --delete root@${1}:/usr/ /mnt/${1}/usr/
rsync -avz --numeric-ids --delete root@${1}:/var/ /mnt/${1}/var/
mount --bind /proc /mnt/${1}/proc/
mount --bind /dev /mnt/${1}/dev
mount --bind /sys /mnt/${1}/sys
chroot /mnt/${1} aptitude -y purge initramfs-tools linux-image-2.6-486 linux-image-2.6.18-4-486 linux-image-2.6.18-5-486 linux-image-2.6.18-6-486 udev grub console-common console-data console-tools smartmontools hddtemp shorewall
chroot /mnt/${1} aptitude -y install libc6-xen
# chroot /mnt/${1} aptitude -y install linux-modules-2.6.18-6-xen-686
umount /mnt/${1}/proc/
umount /mnt/${1}/dev/
umount /mnt/${1}/sys/
rm -rf /mnt/${1}/var/lib/initramfs-tools/*
rm -rf /mnt/${1}/boot/*
rm -rf /mnt/${1}/sys/*
rm -rf /mnt/${1}/proc/*
rm -f /mnt/${1}/etc/udev/rules.d/z25_persistent-net.rules
umount /mnt/${1}
| 1 | #!/bin/bash |
| 2 | if [ -f /etc/default/backuppc-helper ] |
| 3 | then |
| 4 | . /etc/default/backuppc-helper |
| 5 | if [ -z "$VOL" ] |
| 6 | then |
| 7 | echo "#### WARNING ####" |
| 8 | echo "VOL in /etc/default/backuppc-helper not set!" |
| 9 | echo "#################" |
| 10 | exit 0 |
| 11 | fi |
| 12 | else |
| 13 | echo "#### WARNING ####" |
| 14 | echo "/etc/default/backuppc-helper is missing!" |
| 15 | echo "#################" |
| 16 | exit 0 |
| 17 | fi |
| 18 | |
| 19 | if [ `mount | grep ${1} | wc -l` -gt "0" ] ; then |
| 20 | echo "#### WARNING ####" |
| 21 | echo "/dev/${VOL}/${1}-disk already mounted!" |
| 22 | echo "#################" |
| 23 | exit 0 |
| 24 | fi |
| 25 | mkdir -p /mnt/${1} |
| 26 | mount /dev/${VOL}/${1}-disk /mnt/${1} |
| 27 | |
| 28 | rsync -avz --numeric-ids --delete root@${1}:/bin/ /mnt/${1}/bin/ |
| 29 | rsync -avz --numeric-ids --delete root@${1}:/dev/ /mnt/${1}/dev/ |
| 30 | rsync -avz --numeric-ids --delete --exclude=inittab --exclude=network/interfaces --exclude=fstab root@${1}:/etc/ /mnt/${1}/etc/ |
| 31 | rsync -avz --numeric-ids --delete root@${1}:/home/ /mnt/${1}/home/ |
| 32 | rsync -avz --numeric-ids --delete root@${1}:/initrd/ /mnt/${1}/initrd/ |
| 33 | rsync -avz --numeric-ids --delete root@${1}:/lib32/ /mnt/${1}/lib32/ |
| 34 | rsync -avz --numeric-ids --delete root@${1}:/lib/ /mnt/${1}/lib/ |
| 35 | rsync -avz --numeric-ids --delete root@${1}:/lib64 /mnt/${1}/lib64 |
| 36 | rsync -avz --numeric-ids --delete root@${1}:/media/ /mnt/${1}/media/ |
| 37 | rsync -avz --numeric-ids --delete root@${1}:/mnt/ /mnt/${1}/mnt/ |
| 38 | rsync -avz --numeric-ids --delete root@${1}:/opt/ /mnt/${1}/opt/ |
| 39 | rsync -avz --numeric-ids --delete root@${1}:/root/ /mnt/${1}/root/ |
| 40 | rsync -avz --numeric-ids --delete root@${1}:/sbin/ /mnt/${1}/sbin/ |
| 41 | rsync -avz --numeric-ids --delete root@${1}:/srv/ /mnt/${1}/srv/ |
| 42 | #rsync -avz --numeric-ids --delete root@${1}:/sys/ /mnt/${1}/sys/ |
| 43 | rsync -avz --numeric-ids --delete root@${1}:/tmp/ /mnt/${1}/tmp/ |
| 44 | rsync -avz --numeric-ids --delete root@${1}:/usr/ /mnt/${1}/usr/ |
| 45 | rsync -avz --numeric-ids --delete root@${1}:/var/ /mnt/${1}/var/ |
| 46 | |
| 47 | mount --bind /proc /mnt/${1}/proc/ |
| 48 | mount --bind /dev /mnt/${1}/dev |
| 49 | mount --bind /sys /mnt/${1}/sys |
| 50 | chroot /mnt/${1} aptitude -y purge initramfs-tools linux-image-2.6-486 linux-image-2.6.18-4-486 linux-image-2.6.18-5-486 linux-image-2.6.18-6-486 udev grub console-common console-data console-tools smartmontools hddtemp shorewall |
| 51 | chroot /mnt/${1} aptitude -y install libc6-xen |
| 52 | # chroot /mnt/${1} aptitude -y install linux-modules-2.6.18-6-xen-686 |
| 53 | |
| 54 | umount /mnt/${1}/proc/ |
| 55 | umount /mnt/${1}/dev/ |
| 56 | umount /mnt/${1}/sys/ |
| 57 | rm -rf /mnt/${1}/var/lib/initramfs-tools/* |
| 58 | rm -rf /mnt/${1}/boot/* |
| 59 | rm -rf /mnt/${1}/sys/* |
| 60 | rm -rf /mnt/${1}/proc/* |
| 61 | rm -f /mnt/${1}/etc/udev/rules.d/z25_persistent-net.rules |
| 62 | umount /mnt/${1} |
| 63 |