<br><br><div class="gmail_quote">On Sun, Nov 15, 2009 at 9:15 AM, Mr. Teo En Ming (Zhang Enming) <span dir="ltr"><<a href="mailto:space.time.universe@gmail.com">space.time.universe@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><div class="gmail_quote"><div class="im">On Sun, Nov 15, 2009 at 9:11 AM, Mr. Teo En Ming (Zhang Enming) <span dir="ltr"><<a href="mailto:space.time.universe@gmail.com" target="_blank">space.time.universe@gmail.com</a>></span> wrote:<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">
<br><br><div class="gmail_quote">On Fri, Nov 13, 2009 at 10:28 PM, Mr. Teo En Ming (Zhang Enming) <span dir="ltr"><<a href="mailto:space.time.universe@gmail.com" target="_blank">space.time.universe@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div><font size="4"><b>Restore script:</b></font><br><div class="gmail_quote"><br><CODE><br><font size="1">---snipped---</font><br></CODE><br><br><br>
</div>
</div></div></blockquote></div><br>Hi All,<br><br>I have tested my self-written harddisk backup/cloning
script by performing a backup of my Western Digital 500 GB SATA
harddisk to my 160 GB Hitachi harddisk.<br>
<br>The backup operation is successful except for 3 virtual machines.
The backup of these 3 virtual machines fail because partimage does not
support ext4 filesystems. I have performed a backup of these 3 VMs
*again* using the following modified script to handle ext4 filesystems
by using fsarchiver:<br>
<br><SCRIPT><br></div><font size="1">---snipped---</font><div class="im"><br></SCRIPT><br><br>The duration of harddisk cloning has been shortened from 7 hours to 4.5
hours. The filesize of the backup image set has been reduced from 300
GB to 126 GB, which is a substantial reduction of more than 50%.<br clear="all"><br><br></div></blockquote></div><br><font size="4"><b>Latest Backup Script as at 15 November 2009 9:13 A.M. SGT:</b></font><br><br><CODE><br>

<font size="1">---snipped---<br clear="all">
<font size="2"></CODE></font><br></font><br>
</blockquote></div><br><br clear="all"><br><font size="4"><b>Latest Restore Script as at 15 November 2009 Sunday 9:17 A.M. SGT:</b></font><br><br><CODE><br><font size="1">#!/bin/sh<br><br>set -x<br><br>###############################################################################################################<br>
###############################################################################################################<br># Script to Restore Xen Host/Dom0 and all DomUs which are using Logical Volumes as Virtual Hard Disks<br>###############################################################################################################<br>
###############################################################################################################<br><br># Written by:<br> <br># Mr. Teo En Ming (Zhang Enming) Dip(Mechatronics) BEng(Hons)(Mechanical Engineering)<br>
# Alma Maters:<br># (1) Singapore Polytechnic<br># (2) National University of Singapore<br># Primary Blog: <a href="http://teo-en-ming-aka-zhang-enming.blogspot.com">http://teo-en-ming-aka-zhang-enming.blogspot.com</a><br>
# Secondary Blog: <a href="http://enmingteo.wordpress.com">http://enmingteo.wordpress.com</a><br># Youtube Videos: <a href="http://www.youtube.com/user/enmingteo">http://www.youtube.com/user/enmingteo</a><br># Xen Tutorials and Video Demos: <a href="http://www.xen.org/support/tutorial.html">http://www.xen.org/support/tutorial.html</a><br>
# Email: <a href="mailto:space.time.universe@gmail.com">space.time.universe@gmail.com</a><br># MSN: <a href="mailto:teoenming@hotmail.com">teoenming@hotmail.com</a><br># Mobile Phone (Starhub Prepaid): +65-8369-2618<br># Street: Bedok Reservoir Road<br>
# Country: Singapore<br><br># First written: 13 November 2009 Friday 6:49 P.M. Singapore time<br># Last updated: 13 November 2009 Friday 8:25 P.M. Singapore time<br># Last updated: 13 November 2009 Friday 8:59 P.M. Singapore time<br>
# Last updated: 13 November 2009 Friday 9:40 P.M. Singapore time<br># Last updated: 14 November 2009 Saturday 3:31 A.M. Singapore time<br># Last updated: 15 November 2009 Sunday 1:25 A.M. Singapore time<br># Last updated: 15 November 2009 Sunday 8:38 A.M. Singapore time<br>
<br># REFERNCE: "Geek Sheet: Bare-metal backup and recovery", May 7th, 2008, Jason Perlow<br># URL: <a href="http://blogs.zdnet.com/BTL/?p=8759">http://blogs.zdnet.com/BTL/?p=8759</a><br><br># Usage Instructions:<br>
<br># Boot up your desktop/server with System Rescue CD version 1.3.2 for i386/amd64. <br># Then execute this restore script. You need to adapt this script to work for your environment.<br># Download System Rescue CD from <a href="http://www.sysresccd.org/Main_Page">http://www.sysresccd.org/Main_Page</a><br>
<br># No. of QC Checks Performed on this restore script: 1 <br><br>###############################################################################################################<br># Declare Variables<br>###############################################################################################################<br>
<br>HARDDISK=/dev/sda<br>SOURCE=/media/hitachi/test<br><br>###############################################################################################################<br>###############################################################################################################<br>
# Restoring Xen Host/Dom0<br>###############################################################################################################<br>###############################################################################################################<br>
<br># Restore the Master Boot Record<br>dd if=$SOURCE/f11-xen-dom0-sda.mbr of=$HARDDISK bs=512 count=1<br><br># Restore the Partition Geometry<br>sfdisk $HARDDISK < $SOURCE/f11-xen-dom0-partition-geometry-sda.sfdisk<br>
<br># Re-create the LVM2 PV containing the host operating system/dom0<br>#pvcreate --uuid ??? /dev/sda2<br>pvcreate /dev/sda2<br><br># Re-create the LVM2 PV containing all the virtual machines<br>#pvcreate --uuid ??? /dev/sda3<br>
pvcreate /dev/sda3<br><br># Restore the LVM2 metadata for the volume group containing the host operating system/dom0<br>vgcfgrestore --file $SOURCE/vg_fedora11_host-vgcfg.lvm2.metadata vg_fedora11_host<br><br># Restore the LVM2 metadata for the volume group containing all the virtual machines<br>
vgcfgrestore --file $SOURCE/virtualmachines-vgcfg.lvm2.metadata virtualmachines<br><br># Activate all the volume groups<br>vgchange -ay<br><br># Restore all filesystems for the host operating system/dom0<br>fsarchiver restfs -v $SOURCE/f11-xen-dom0-filesystems.fsa id=0,dest=/dev/sda1 \<br>
id=1,dest=/dev/vg_fedora11_host/lv_home \<br>id=2,dest=/dev/vg_fedora11_host/lv_root \<br>id=3,dest=/dev/vg_fedora11_host/lv_var<br><br># Re-create the swap partition<br>mkswap /dev/vg_fedora11_host/lv_swap<br><br>###############################################################################################################<br>
###############################################################################################################<br># Restoring Xen-based Virtual Machines/DomUs/Guest Operating Systems/VMs<br>###############################################################################################################<br>
###############################################################################################################<br><br>### NOTE: Check for swap partitions in each virtual machine and do a mkswap.<br><br># VM 1: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>
###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0001.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0001<br>
<br># VM 2: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0002.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0002<br>
<br># VM 3: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0003.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0003<br>
<br># VM 4: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0004.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0004<br>
<br># VM 5: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0005.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0005<br>
<br># VM 6: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0006.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0006<br>
<br># VM 7: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0007.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0007<br>
<br># VM 8: Fedora 11 x86_64 PV domU (MPICH2 Virtual Supercomputer Center)<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-f11-pv-hpc-node0008.img.gz | dd of=/dev/virtualmachines/f11-pv-hpc-node0008<br>
<br># VM 9: FreeBSD 8.0 RC2 UNIX amd64 HVM domU<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-freebsd.img.gz | dd of=/dev/virtualmachines/freebsd<br>
<br># VM 10: OpenSolaris 2009.06 UNIX amd64 PV domU<br>###############################################################################################################<br><br>zcat $SOURCE/virtualmachines-opensolaris.img.gz | dd of=/dev/virtualmachines/opensolaris<br>
<br># VM 11: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>
kpartx -av /dev/virtualmachines/rocks0001<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-rocks0001.mbr of=/dev/virtualmachines/rocks0001 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/rocks0001 < $SOURCE/virtualmachines-rocks0001.sfdisk<br>
<br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p1 $SOURCE/virtualmachines-rocks0001p1.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p2 $SOURCE/virtualmachines-rocks0001p2.img.000<br>
<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0001p5 $SOURCE/virtualmachines-rocks0001p5.img.000<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0001p3<br><br># Delete partition mappings in /dev/mapper<br>
kpartx -dv /dev/virtualmachines/rocks0001<br><br># VM 12: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>###############################################################################################################<br>
<br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/rocks0002<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-rocks0002.mbr of=/dev/virtualmachines/rocks0002 bs=512 count=1<br><br># Restore partition geometry<br>
sfdisk /dev/virtualmachines/rocks0002 < $SOURCE/virtualmachines-rocks0002.sfdisk<br><br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p1 $SOURCE/virtualmachines-rocks0002p1.img.000<br>
<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p2 $SOURCE/virtualmachines-rocks0002p2.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0002p5 $SOURCE/virtualmachines-rocks0002p5.img.000<br>
<br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0002p3<br><br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/rocks0002<br><br># VM 13: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>
###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/rocks0003<br><br># Restore MBR<br>
dd if=$SOURCE/virtualmachines-rocks0003.mbr of=/dev/virtualmachines/rocks0003 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/rocks0003 < $SOURCE/virtualmachines-rocks0003.sfdisk<br><br>
# Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p1 $SOURCE/virtualmachines-rocks0003p1.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p2 $SOURCE/virtualmachines-rocks0003p2.img.000<br>
<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0003p5 $SOURCE/virtualmachines-rocks0003p5.img.000<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0003p3<br><br># Delete partition mappings in /dev/mapper<br>
kpartx -dv /dev/virtualmachines/rocks0003<br><br># VM 14: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>###############################################################################################################<br>
<br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/rocks0004<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-rocks0004.mbr of=/dev/virtualmachines/rocks0004 bs=512 count=1<br><br># Restore partition geometry<br>
sfdisk /dev/virtualmachines/rocks0004 < $SOURCE/virtualmachines-rocks0004.sfdisk<br><br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p1 $SOURCE/virtualmachines-rocks0004p1.img.000<br>
<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p2 $SOURCE/virtualmachines-rocks0004p2.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0004p5 $SOURCE/virtualmachines-rocks0004p5.img.000<br>
<br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0004p3<br><br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/rocks0004<br><br># VM 15: Rocks 5.1 x86_64 HPC Compute Cluster HVM domU (based on CentOS 5.2)<br>
###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/rocks0005<br><br># Restore MBR<br>
dd if=$SOURCE/virtualmachines-rocks0005.mbr of=/dev/virtualmachines/rocks0005 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/rocks0005 < $SOURCE/virtualmachines-rocks0005.sfdisk<br><br>
# Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p1 $SOURCE/virtualmachines-rocks0005p1.img.000<br><br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p2 $SOURCE/virtualmachines-rocks0005p2.img.000<br>
<br>partimage -e -b restore /dev/mapper/virtualmachines-rocks0005p5 $SOURCE/virtualmachines-rocks0005p5.img.000<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-rocks0005p3<br><br># Delete partition mappings in /dev/mapper<br>
kpartx -dv /dev/virtualmachines/rocks0005<br><br># VM 16: Slackware64 13.0 amd64 HVM domU<br>###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>
kpartx -av /dev/virtualmachines/slackware64<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-slackware64.mbr of=/dev/virtualmachines/slackware64 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/slackware64 < $SOURCE/virtualmachines-slackware64.sfdisk<br>
<br># Restore all filesystems<br># partimage does not support ext4 filesystems<br>#partimage -e -b restore /dev/mapper/virtualmachines-slackware64p1 $SOURCE/virtualmachines-slackware64p1.img.000<br><br>#partimage -e -b restore /dev/mapper/virtualmachines-slackware64p2 $SOURCE/virtualmachines-slackware64p2.img.000<br>
<br>fsarchiver restfs -v $SOURCE/virtualmachines-slackware64p1.fsa \<br>id=0,dest=/dev/mapper/virtualmachines-slackware64p1<br><br>fsarchiver restfs -v $SOURCE/virtualmachines-slackware64p2.fsa \<br>id=0,dest=/dev/mapper/virtualmachines-slackware64p2<br>
<br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-slackware64p3<br><br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/slackware64<br><br># VM 17: Ubuntu 9.10 Karmic Koala Linux HVM domU<br>
###############################################################################################################<br><br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/ubuntu910<br><br># Restore MBR<br>
dd if=$SOURCE/virtualmachines-ubuntu910.mbr of=/dev/virtualmachines/ubuntu910 bs=512 count=1<br><br># Restore partition geometry<br>sfdisk /dev/virtualmachines/ubuntu910 < $SOURCE/virtualmachines-ubuntu910.sfdisk<br><br>
# Restore all filesystems<br># partimage does not support ext4 filesystems<br>#partimage -e -b restore /dev/mapper/virtualmachines-ubuntu910p1 $SOURCE/virtualmachines-ubuntu910p1.img.000<br><br>fsarchiver restfs -v $SOURCE/virtualmachines-ubuntu910p1.fsa \<br>
id=0,dest=/dev/mapper/virtualmachines-ubuntu910p1<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-ubuntu910p5<br><br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/ubuntu910<br>
<br># VM 18: Windows XP Home Edition SP3 32-bit HVM domU with VGA passthrough (requires Intel VT-d)<br>###############################################################################################################<br><br>
# Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/winxphome32<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-winxphome32.mbr of=/dev/virtualmachines/winxphome32 bs=512 count=1<br><br># Restore partition geometry<br>
sfdisk /dev/virtualmachines/winxphome32 < $SOURCE/virtualmachines-winxphome32.sfdisk<br><br># Restore all filesystems<br>partimage -e -b restore /dev/mapper/virtualmachines-winxphome32p1 $SOURCE/virtualmachines-winxphome32p1.img.000<br>
<br># Delete partition mappings in /dev/mapper<br>kpartx -dv /dev/virtualmachines/winxphome32<br><br># VM 19: openSUSE 11.2 x86_64 Linux PV domU<br>###############################################################################################################<br>
<br># Add partition mappings in /dev/mapper<br>kpartx -av /dev/virtualmachines/opensuse<br><br># Restore MBR<br>dd if=$SOURCE/virtualmachines-opensuse.mbr of=/dev/virtualmachines/opensuse bs=512 count=1<br><br># Restore partition geometry<br>
sfdisk /dev/virtualmachines/opensuse < $SOURCE/virtualmachines-opensuse.sfdisk<br><br># Restore all filesystems<br># partimage does not support ext4 filesystems<br>#partimage -e -b restore /dev/mapper/virtualmachines-opensuse2 $SOURCE/virtualmachines-opensuse2.img.000<br>
<br>fsarchiver restfs -v $SOURCE/virtualmachines-opensuse2.fsa id=0,dest=/dev/mapper/virtualmachines-opensuse2<br><br># Re-create swap<br>mkswap /dev/mapper/virtualmachines-opensuse1<br><br># Delete partition mappings in /dev/mapper<br>
kpartx -dv /dev/virtualmachines/opensuse<br><br>###############################################################################################################<br>###############################################################################################################<br>
<br># Deactivate Logical Volume Manager<br>vgchange -an<br><br># Sync filesystems<br>sync<br><br># Reboot the machine<br>reboot<br><br>###############################################################################################################<br>
# EOF<br>###############################################################################################################</font><br></CODE><br><br>