XS Backup and Recovery with SysRescueCD: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 8: Line 8:
[[XS_Backup_and_Disaster_Recovery Using Mondo Rescue ]] )
[[XS_Backup_and_Disaster_Recovery Using Mondo Rescue ]] )


Backing up your XS School Server
Step 1.

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

Capture all of the RPM packages installed. This should be done from
a running XS schoolserver system. The rest of the steps will be done
by booting from CD, but this is done from the running XS schoolserver itself.
<tt>
<tt>
[root ~]# cd /root
[root ~]# cd /root
Line 16: Line 20:
</tt>
</tt>


Step 2.
Step 2. Boot from SysRescueCD

Boot from the [[http://www.sysresccd.org/Main_Page SysRescueCD]] cd. If you plan to burn CD or DVD media, specify
Boot from the [[http://www.sysresccd.org/Main_Page SysRescueCD]] cd. If you plan to burn CD or DVD media, specify the "docache" parameter which copies the entire contents of the CD into memory, so you need at least 1GB of RAM to use this option.


'''boot:''' rescuecd docache
'''boot:''' rescuecd docache


If you are backing up to internal drive or external USB instead, you don't need the "docache" option, you can just press enter at "boot:" prompt.


Step 3. Make a directory to put your backups into
<tt>
[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
</tt>


If you are burning to CD, we will temporarily use the
Capture the file system table (fstab). These are the file systems mounted at boot time.
/library directory on the XS hard disk, and then backup everything to CD. The "/mnt/backup" is already defined in the SysRescCD, so no need to "mkdir" for it. We will create a subdirectory with a date to remember when this was taken.
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.


<tt>
<tt>
# Step 3--to CD or DVD
[root ~]# cd /root
umount /library
[root ~]# cp /etc/fstab etc-fstab.prep
mount /vol/VolGroup00/LogVol00 /mnt/backup
[root ~]# cat etc-fstab.prep
mkdir /mnt/backup/June18-2008
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
</tt>
</tt>


If we are backing up to an external USB disk instead, a few commands are different.
Capture the disk layout. We will be making a new disk layout, but this information
You can boot up with the USB drive attached, or attach after the SysRescCD is up and running. Use these commands to help you figure out which device is appropriate for your USB device. I am using a 320GB drive in my examples, and found that it was attached at /dev/sdf1. My USB device is formatted FAT32 so that it can be used with Windows as well.
could be helpful during re-assembly.


<tt>
<tt>
# Step 3--to External FAT32-formatted USB drive
[root ~]# cd /root
dmesg | grep usb
[root ~]# sfdisk -d /dev/sda > sfdisk-d.prep
ls /dev/sd*
[root ~]# cat sfdisk-d.prep
mount -t vfat /dev/sdf1 /mnt/backup
# partition table of /dev/sda
mkdir /mnt/backup/June18-2008
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
</tt>
</tt>


Step 6.
Step 4.
Backup the Master Boot Record and Disk Layout, and any LVM2 logical volume
We will now backup this OS image. These backups will then
management configuration. The commands will run from whatever directory you are currently in, but I find it is easiest to switch to the destination directory so that there is less typing.
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.


<tt>
<tt>
[root ~]# cd /root
[root ~]# cd /mnt/backup/June18-2008
[root /mnt/backup/June18-2008]# dd if=/dev/sda of=xs163.mbr bs=446 count=1
[root ~]# mke2fs -L BACKUP -j /dev/sdb2
[root /mnt/backup/June18-2008]# sfdisk -d > sfdisk-d.txt
[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]
</tt>
</tt>


Step 5.
We will copy the information we captured in step 5 over to the backup directory.
Now we are going to copy specific files that
would be nice to be able to read from the backup media directly, without restore. All of
these are optional, so you can skip this step if you are in a hurry. You can include other files like your own README or special scripts. I find it is easiest to switch to the destination directory and copy files from various sources.


<tt>
<tt>
[root ~]# cp /mnt/base/root/*.prep /mnt/backup
[root ~]# cd /mnt/backup/June18-2008
[root /mnt/backup/June18-2008]# cp -L /boot/grub/menu.lst grubmenu.txt
[root /mnt/backup/June18-2008]# cp /root/rpm-qa.txt .
[root /mnt/backup/June18-2008]# cp /etc/fstab etcfstab.txt
[root /mnt/backup/June18-2008]# fdisk -l > fdisk-l.txt
[root /mnt/backup/June18-2008]# pvdisplay > pvdisplay.txt
[root /mnt/backup/June18-2008]# vgdisplay > vgdisplay.txt
[root /mnt/backup/June18-2008]# lvdisplay > lvdisplay.txt
</tt>
</tt>


Step 6.
We will now invoke ''partimage'' utility to perform the backups. ''partimage'' works
We will now invoke ''partimage'' utility to perform the backups. ''partimage'' works
with partitions that contain file systems, including logical volumes. Only the actual
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
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
mounted during the partimage processing. Here are the compression options:

required, as it is only a few MB in size. For the root partition, we use -z1 for ''gzip''
* z0 -- means no compression, backups will be done very fast
compression, and use "-V660" to indicate that the image should be split into pieces
* z1 -- means gzip compression, this may take a few minutes, but will result in smaller outpu
* z2 -- means bzip2 compression, takes much longer but creates the smallest output

I'll use z0 for /boot directory which is small, and z1 for the / (root) directory.
I specify the "-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
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.
can hold 700MB. Check your media for capacity. This is a good idea even if you are
backing up to an external USB FAT32 drive, as FAT32 can only hold 2GB images maximum,
so splitting them up into small pieces guarantees they won't encounter any FAT32 size
limits.


<tt>
<tt>
[root /mnt/backup/June18-2008]# partimage -d -b -z0 save /dev/sda1 sda1-BOOT.img
[root ~]# cd /mnt/backup
[root /mnt/backup]# umount /mnt/boot
[root /mnt/backup/June18-2008]# partimage -d -b -z1 -V660 save /dev/sda2 sda2-XS163.img
[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)
Volume size: 692060160 bytes (660 MiB)
</tt>
</tt>


Step 7.
Thanks to compression, the entire backup directory is only 1.1GB in size. This could
Thanks to compression, my 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
be burned onto two CDs or one DVD. In this case, we use ''growisofs'' to burn the list
of files onto a single DVD.
of files onto a single DVD.


<tt>
<tt>
[root /mnt/backup]# ls
[root /mnt/backup/June18-2008]# ls
boot-grub-menu.prep rpm-qa.prep sda2-FEDORA7.img.000 sfdisk-d.prep
grubmenu.txt rpm-qa.prep sda2-xs.img.000 sfdisk-d.txt
etc-fstab.prep sda1-BOOT.img.000 sda2-FEDORA7.img.001
etcfstab.txt sda1BOOT.img.000 sda2-xs.img.001 xs163.mbr
[root /mnt/backup]# du -sh
[root /mnt/backup/June18-2008]# du -sh
1.1G .
1.1G .
[root /mnt/backup]# growisofs -Z /dev/dvd -R -J /mnt/backup/*
[root /mnt/backup/June18-2008]# growisofs -Z /dev/dvd -R -J /mnt/backup/*
...
...
99.05% done, estimate finish Tue Jun 17 15:56:46 2008
99.05% done, estimate finish Tue Jun 17 15:56:46 2008
Line 156: Line 125:
/dev/dvd: updating RMA
/dev/dvd: updating RMA
/dev/dvd: closing session
/dev/dvd: closing session
[root /mnt/backup]# cd /root
[root /mnt/backup/June18-2008]# cd /root
[root /mnt/backup]# umount /mnt/backup
[root ~]# umount /mnt/backup
[root /mnt/backup]# sync
[root ~]# sync
[root /mnt/backup]# eject
</tt>
</tt>

Recovering your XS School Server

Latest revision as of 18:49, 19 June 2008

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 )

Backing up your XS School Server

Step 1. Capture RPM package list

Capture all of the RPM packages installed. This should be done from a running XS schoolserver system. The rest of the steps will be done by booting from CD, but this is done from the running XS schoolserver itself.

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

Step 2. Boot from SysRescueCD

Boot from the [SysRescueCD] cd. If you plan to burn CD or DVD media, specify the "docache" parameter which copies the entire contents of the CD into memory, so you need at least 1GB of RAM to use this option.

boot: rescuecd docache

If you are backing up to internal drive or external USB instead, you don't need the "docache" option, you can just press enter at "boot:" prompt.

Step 3. Make a directory to put your backups into

If you are burning to CD, we will temporarily use the /library directory on the XS hard disk, and then backup everything to CD. The "/mnt/backup" is already defined in the SysRescCD, so no need to "mkdir" for it. We will create a subdirectory with a date to remember when this was taken.

# Step 3--to CD or DVD
umount /library
mount /vol/VolGroup00/LogVol00 /mnt/backup
mkdir /mnt/backup/June18-2008

If we are backing up to an external USB disk instead, a few commands are different. You can boot up with the USB drive attached, or attach after the SysRescCD is up and running. Use these commands to help you figure out which device is appropriate for your USB device. I am using a 320GB drive in my examples, and found that it was attached at /dev/sdf1. My USB device is formatted FAT32 so that it can be used with Windows as well.

# Step 3--to External FAT32-formatted USB drive
dmesg | grep usb
ls /dev/sd*
mount -t vfat /dev/sdf1 /mnt/backup
mkdir /mnt/backup/June18-2008

Step 4. Backup the Master Boot Record and Disk Layout, and any LVM2 logical volume management configuration. The commands will run from whatever directory you are currently in, but I find it is easiest to switch to the destination directory so that there is less typing.

[root ~]# cd /mnt/backup/June18-2008
[root /mnt/backup/June18-2008]# dd if=/dev/sda of=xs163.mbr bs=446 count=1
[root /mnt/backup/June18-2008]# sfdisk -d > sfdisk-d.txt

Step 5. Now we are going to copy specific files that would be nice to be able to read from the backup media directly, without restore. All of these are optional, so you can skip this step if you are in a hurry. You can include other files like your own README or special scripts. I find it is easiest to switch to the destination directory and copy files from various sources.

[root ~]# cd /mnt/backup/June18-2008
[root /mnt/backup/June18-2008]# cp -L /boot/grub/menu.lst grubmenu.txt
[root /mnt/backup/June18-2008]# cp /root/rpm-qa.txt .
[root /mnt/backup/June18-2008]# cp /etc/fstab  etcfstab.txt
[root /mnt/backup/June18-2008]# fdisk -l > fdisk-l.txt
[root /mnt/backup/June18-2008]# pvdisplay > pvdisplay.txt
[root /mnt/backup/June18-2008]# vgdisplay > vgdisplay.txt
[root /mnt/backup/June18-2008]# lvdisplay > lvdisplay.txt

Step 6. 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. Here are the compression options:

  • z0 -- means no compression, backups will be done very fast
  • z1 -- means gzip compression, this may take a few minutes, but will result in smaller outpu
  • z2 -- means bzip2 compression, takes much longer but creates the smallest output

I'll use z0 for /boot directory which is small, and z1 for the / (root) directory. I specify the "-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. This is a good idea even if you are backing up to an external USB FAT32 drive, as FAT32 can only hold 2GB images maximum, so splitting them up into small pieces guarantees they won't encounter any FAT32 size limits.

[root /mnt/backup/June18-2008]# partimage -d -b -z0 save /dev/sda1 sda1-BOOT.img
[root /mnt/backup/June18-2008]# partimage -d -b -z1 -V660 save /dev/sda2 sda2-XS163.img
Volume size: 692060160 bytes (660 MiB)

Step 7. Thanks to compression, my 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/June18-2008]# ls
grubmenu.txt  rpm-qa.prep       sda2-xs.img.000  sfdisk-d.txt
etcfstab.txt  sda1BOOT.img.000  sda2-xs.img.001  xs163.mbr
[root /mnt/backup/June18-2008]# du -sh
1.1G    .
[root /mnt/backup/June18-2008]# 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/June18-2008]# cd /root
[root ~]#  umount /mnt/backup
[root ~]#  sync

Recovering your XS School Server