XS Backup and Recovery with SysRescueCD

From OLPC
Revision as of 14:04, 19 June 2008 by Az990tony (talk | contribs)
Jump to: navigation, search

This page will show how you can perform a full system backup (suitable for disaster recovery) of an XS School Server using [SysRescueCD]. This method can backup up to 700MB CD media, 4.7GB DVD media, or USB external storage.

( Alternative methods include XS_backup_restore Using rsync and XS_Backup_and_Disaster_Recovery Using Mondo Rescue )

Step 1. Capture all of the RPM packages installed. This can only be done from a running system.

[root ~]# cd /root
[root ~]# rpm -qa | sort > rpm-qa.txt

Step 2. Boot from the [SysRescueCD] cd. If you plan to burn CD or DVD media, specify

boot: rescuecd docache


[root ~]# cd /root
[root ~]# cp /boot/grub/menu.lst boot-grub-menu.prep
[root ~]# cat boot-grub-menu.prep
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/pdc_bbbhp2
#          initrd /initrd-version.img
#boot=/dev/mapper/pdc_bbbh
default=0
timeout=30
splashimage=(hd0,0)/grub/splash.xpm.gz
#hiddenmenu
title Fedora7 (2.6.23.17-88.fc7)
       root (hd0,0)
       kernel /vmlinuz-2.6.23.17-88.fc7 ro root=LABEL=FEDORA7
       initrd /initrd-2.6.23.17-88.fc7.img

Capture the file system table (fstab). These are the file systems mounted at boot time. Notice that I use LABEL=FEDORA7 for the root directory, LABEL=BOOT for the boot directory, and LABEL=SWAP1 for the swap space. Using LABEL= will make the process easier when we re-assemble all of the pieces into the final system.

[root ~]# cd /root
[root ~]# cp /etc/fstab etc-fstab.prep
[root ~]# cat etc-fstab.prep
LABEL=FEDORA7           /                       ext3    defaults        1 1
LABEL=BOOT              /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP1             none                    swap    defaults        0 0

Capture the disk layout. We will be making a new disk layout, but this information could be helpful during re-assembly.

[root ~]# cd /root
[root ~]# sfdisk -d /dev/sda > sfdisk-d.prep
[root ~]# cat sfdisk-d.prep
# partition table of /dev/sda
unit: sectors
/dev/sda1 : start=       63, size=  1285137, Id=83, bootable
/dev/sda2 : start=  1285200, size= 64581300, Id=83
/dev/sda3 : start=        0, size=        0, Id= 0
/dev/sda4 : start= 65866500, size=  4305420, Id= 5
/dev/sda5 : start= 65866563, size=  4305357, Id=82

Step 6. We will now backup this OS image. These backups will then be used to re-assemble the final system. For this example, I will use /dev/sdb3 (ext3) as temporary space to hold the backup images, and then burn onto DVD. If you have a large external USB drive, you could use that instead. To get a clean backup, I will boot from [[ http://sysresccd.org/Main_Page | SysRescCD 1.0.3 ]] and perform all my work from there. We see that /mnt/boot has only 19MB of data, and /mnt/base has 3.3GB of data. Both could fit on a single DVD. The "mount -l" shows that everything is mounted successfully.

[root ~]#   cd /root
[root ~]#   mke2fs -L BACKUP -j /dev/sdb2
[root ~]#   mkdir /mnt/boot /mnt/base /mnt/backup
[root ~]#   mount /dev/sda1 /mnt/boot
[root ~]#   mount /dev/sda2 /mnt/base
[root ~]#   mount /dev/sdb2 /mnt/backup
[root ~]#   du -sh /mnt/boot /mnt/base
19M     /mnt/boot
3.3G    /mnt/base
[root ~]#   mount -l
tmpfs on / type tmpfs (rw)
/dev/loop0 on /mnt/livecd type squashfs (ro,relatime)
tmpfs on /mnt/cdrom type tmpfs (rw,relatime,size=204800k)
...
/dev/sda1 on /mnt/boot type ext3 (rw) [BOOT]
/dev/sda2 on /mnt/base type ext3 (rw) [FEDORA7]
/dev/sdb3 on /mnt/backup type ext3 (rw) [BACKUP]

We will copy the information we captured in step 5 over to the backup directory.

[root ~]#  cp /mnt/base/root/*.prep /mnt/backup

We will now invoke partimage utility to perform the backups. partimage works with partitions that contain file systems, including logical volumes. Only the actual data is backed up, and compression options are available. The partitions must not be mounted during the partimage processing. For BOOT, -z0 indicates no compression is required, as it is only a few MB in size. For the root partition, we use -z1 for gzip compression, and use "-V660" to indicate that the image should be split into pieces small enough to be burned onto a CDrom. (660 MiB is approximately 692 MB, and most CDrom can hold 700MB. Check your media for capacity.

[root ~]#  cd /mnt/backup
[root /mnt/backup]#  umount /mnt/boot
[root /mnt/backup]#  umount /mnt/base
[root /mnt/backup]#  sync
[root /mnt/backup]#  partimage -d -b -z0 save /dev/sda1 sda1-BOOT.img
[root /mnt/backup]#  partimage -d -b -z1 -V660 save /dev/sda1 sda1-BOOT.img
Volume size: 692060160 bytes (660 MiB)

Thanks to compression, the entire backup directory is only 1.1GB in size. This could be burned onto two CDs or one DVD. In this case, we use growisofs to burn the list of files onto a single DVD.

[root /mnt/backup]#  ls
boot-grub-menu.prep  rpm-qa.prep        sda2-FEDORA7.img.000  sfdisk-d.prep
etc-fstab.prep       sda1-BOOT.img.000  sda2-FEDORA7.img.001
[root /mnt/backup]#  du -sh
1.1G    .
[root /mnt/backup]#  growisofs -Z /dev/dvd -R -J /mnt/backup/*
...
99.05% done, estimate finish Tue Jun 17 15:56:46 2008
Total translation table size: 0
Total rockridge attributes bytes: 874
Total directory bytes: 0
Path table size(bytes): 10
Max brk space used 0
535076 extents written (1045 MB)
builtin_dd: 535088*2KB out @ average 7.9x1352KBps
/dev/dvd: flushing cache
/dev/dvd: updating RMA
/dev/dvd: closing session
[root /mnt/backup]#  cd /root
[root /mnt/backup]#  umount /mnt/backup
[root /mnt/backup]#  sync
[root /mnt/backup]#  eject