Using the restore command to recover an entire system from network backups
---------------------

Install Linux (any version) on a blank hard drive. Make sure there is plenty of disk space left
after the installation to create additional partitions large enough to hold all of the backup
data to be restored.

Configure the new Linux install for network access. In this example we'll give the new machine
the name 'fanta'. Use 'up2date' or 'yum' to apply any security updates.

Use fdisk to list your current partition scheme:
[root@fanta ~]# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap

Use df to see how each partition is used:
[root@fanta ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda2              27G  2.0G   23G   8% /
/dev/hda1              99M  5.2M   89M   6% /boot
/dev/shm              252M     0  252M   0% /dev/shm
//fanta/backups       30G   24G  5.9G  80% /mnt/fanta/backups

Use fdisk to create an extended partition on /dev/hda. Here is what that process looks like:
[root@fanta ~]# fdisk /dev/hda

The number of cylinders for this disk is set to 9729.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (4922-9729, default 4922):
Using default value 4922
Last cylinder or +size or +sizeM or +sizeK (4922-9729, default 9729):
Using default value 9729

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap / Solaris
/dev/hda4            4922        9729    38620260    5  Extended

Command (m for help): n
First cylinder (4922-9729, default 4922):
Using default value 4922
Last cylinder or +size or +sizeM or +sizeK (4922-9729, default 9729): +100M

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap / Solaris
/dev/hda4            4922        9729    38620260    5  Extended
/dev/hda5            4922        4934      104391   83  Linux

Command (m for help): n
First cylinder (4935-9729, default 4935):
Using default value 4935
Last cylinder or +size or +sizeM or +sizeK (4935-9729, default 9729): +28000M

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap / Solaris
/dev/hda4            4922        9729    38620260    5  Extended
/dev/hda5            4922        4934      104391   83  Linux
/dev/hda6            4935        8339    27350631   83  Linux

Command (m for help): n
First cylinder (8340-9729, default 8340):
Using default value 8340
Last cylinder or +size or +sizeM or +sizeK (8340-9729, default 9729):
Using default value 9729

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap / Solaris
/dev/hda4            4922        9729    38620260    5  Extended
/dev/hda5            4922        4934      104391   83  Linux
/dev/hda6            4935        8339    27350631   83  Linux
/dev/hda7            8340        9729    11165143+  83  Linux

Command (m for help): d
Partition number (1-7): 7

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap / Solaris
/dev/hda4            4922        9729    38620260    5  Extended
/dev/hda5            4922        4934      104391   83  Linux
/dev/hda6            4935        8339    27350631   83  Linux

Command (m for help): n
First cylinder (8340-9729, default 8340):
Using default value 8340
Last cylinder or +size or +sizeM or +sizeK (8340-9729, default 9729): +1500M

Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): 82
Changed system type of partition 7 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap / Solaris
/dev/hda4            4922        9729    38620260    5  Extended
/dev/hda5            4922        4934      104391   83  Linux
/dev/hda6            4935        8339    27350631   83  Linux
/dev/hda7            8340        8522     1469916   82  Linux swap / Solaris

Command (m for help): n
First cylinder (8523-9729, default 8523):
Using default value 8523
Last cylinder or +size or +sizeM or +sizeK (8523-9729, default 9729):
Using default value 9729

Command (m for help): p

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap / Solaris
/dev/hda4            4922        9729    38620260    5  Extended
/dev/hda5            4922        4934      104391   83  Linux
/dev/hda6            4935        8339    27350631   83  Linux
/dev/hda7            8340        8522     1469916   82  Linux swap / Solaris
/dev/hda8            8523        9729     9695196   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

[root@fanta ~]# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        4730    37889302+  83  Linux
/dev/hda3            4731        4921     1534207+  82  Linux swap / Solaris
/dev/hda4            4922        9729    38620260    5  Extended
/dev/hda5            4922        4934      104391   83  Linux
/dev/hda6            4935        8339    27350631   83  Linux
/dev/hda7            8340        8522     1469916   82  Linux swap / Solaris
/dev/hda8            8523        9729     9695196   83  Linux

In the partitioning scheme above hda1, hda2 and hda3 are partitions of the Linux install currently
in use. We created an extended partition for the remaining unused disk space (about 39G) and create
four new partitions:
/dev/hda5 is ~100Mb and will be the new boot partition
/dev/hda6 is  ~27Gb and will be the new root partition
/dev/hda7 is ~1.5Gb and will be the new Linux swap partition
/dev/hda8 is  ~10Gb and will become a data partition

Reboot the system to make new partition changes take effect.

Use mkfs to create a file system on hda6:
[root@fanta ~]# mkfs /dev/hda5
mke2fs 1.37 (21-Mar-2005)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
26104 inodes, 104388 blocks
5219 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@fanta ~]#

Repeat this process for hda6, hda7 and hda8.
[root@fanta ~]# mkfs /dev/hda6
[root@fanta ~]# mkfs /dev/hda7
[root@fanta ~]# mkfs /dev/hda8

Now let's assume you have a Windows machine on the network named bravo containing the save sets
you want to restore and you've shared the folder 'backups'. Create a local directory for mounting
the network share:
[root@fanta ~]# mkdir /mnt/bravo/backups

Mount the remote file system:
[root@fanta ~]# mount -t smbfs -o username=bravoadmin,password=$ecur3pa$$word //bravo/backups /mnt/bravo/backups

Use df to confirm the network mount succeeded:
[root@fanta ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda2              27G  1.9G   23G   8% /
/dev/hda1              99M  5.2M   89M   6% /boot
/dev/shm              252M     0  252M   0% /dev/shm
//bravo/backups       30G   24G  5.9G  80% /mnt/bravo/backups

List backup volumes to be restored:
[root@fanta ~]# ls -la /mnt/bravo/backups/
total 11254722
drwxr-xr-x  1 root root       4096 Feb  3 07:32 .
drwxr-xr-x  3 root root       4096 Feb  2 16:15 ..
-rwxr-xr-x  1 root root   15697920 Feb  1 17:15 boot
-rwxr-xr-x  1 root root     419840 Feb  1 17:16 data
-rwxr-xr-x  1 root root 2143283200 Feb  1 20:52 root_vol1
-rwxr-xr-x  1 root root 2143283200 Feb  1 21:34 root_vol2
-rwxr-xr-x  1 root root 2143283200 Feb  2 10:00 root_vol3
-rwxr-xr-x  1 root root 2143283200 Feb  2 10:35 root_vol4
-rwxr-xr-x  1 root root 2143283200 Feb  2 11:19 root_vol5
-rwxr-xr-x  1 root root  792289280 Feb  2 11:35 root_vol6

First we restore the boot partition:
[root@fanta ~]# mkdir /mnt/workingdir
[root@fanta ~]# mount /dev/hda5 /mnt/workingdir
[root@fanta ~]# cd /mnt/workingdir
[root@fanta workingdir]# restore rf /mnt/bravo/backups/boot
restore: ./lost+found: File exists
[root@fanta workingdir]# cd ~
[root@fanta ~]#

Next we restore the data partition:
[root@fanta ~]# mount /dev/hda8 /mnt/workingdir
[root@fanta ~]# cd /mnt/workingdir
[root@fanta workingdir]# restore rf /mnt/bravo/backups/data
restore: ./lost+found: File exists
[root@fanta workingdir]# cd ~
[root@fanta ~]#

Finally we restore the root partition one volume at a time:
[root@fanta ~]# mount /dev/hda6 /mnt/workingdir
[root@fanta ~]# cd /mnt/workingdir
[root@fanta workingdir]# restore rf /mnt/bravo/backups/root_vol1
restore: ./lost+found: File exists
./.journal: (inode 13) not found on tape
Mount tape volume 2
Enter ``none'' if there are no more tapes
otherwise enter tape name (default: /mnt/fanta/backups/root_vol1) /mnt/fanta/backups/root_vol2
Mount tape volume 3
Enter ``none'' if there are no more tapes
otherwise enter tape name (default: /mnt/fanta/backups/root_vol2) /mnt/fanta/backups/root_vol3

Mount tape volume 4
Enter ``none'' if there are no more tapes
otherwise enter tape name (default: /mnt/fanta/backups/root_vol3) /mnt/fanta/backups/root_vol4

Mount tape volume 5
Enter ``none'' if there are no more tapes
otherwise enter tape name (default: /mnt/fanta/backups/root_vol4) /mnt/fanta/backups/root_vol5

Mount tape volume 6
Enter ``none'' if there are no more tapes
otherwise enter tape name (default: /mnt/fanta/backups/root_vol5) /mnt/fanta/backups/root_vol6

Unmount the network share on 'bravo':
[root@fanta ~]# umount //bravo/backups
[root@fanta workingdir]#

[root@fanta workingdir]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda2              27G  1.9G   23G   8% /
/dev/hda1              99M  5.2M   89M   6% /boot
/dev/shm              252M     0  252M   0% /dev/shm
//fanta/backups       30G   24G  5.9G  80% /mnt/fanta/backups
/dev/hda6              26G   11G   14G  44% /mnt/workingdir

Make a backup copy of the current version of 'fstab':
{root@fanta workingdir]# cp /etc/fstab /etc/fstab.back 
[root@fanta workingdir]# cp /mnt/workingdir/etc/fstab /etc/fstab
cp: overwrite `/etc/fstab'? yes
[root@fanta workingdir]# more /etc/fstab
/dev/hda1               /data                   ext3    defaults        0 0
#/dev/hda1               /mnt/win98              vfat   defaults        0 0
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
/dev/fd0                /mnt/floppy             auto    noauto,owner    0 0
none                    /proc                   proc    defaults        0 0
none                    /dev/shm                tmpfs   defaults        0 0
none                    /dev/pts                devpts  gid=5,mode=620  0 0
/dev/hda5               swap                    swap    defaults        0 0
/usr/swap0              swap                    swap    defaults        0 0
/dev/sda1               /usb1                   vfat    defaults,user,noauto    0       0
/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0

After editing the file it should look like this:
/dev/hda8               /data                   ext3    defaults        0 0
#/dev/hda1              /mnt/win98              vfat    defaults        0 0
/dev/hda6               /                       ext3    defaults        1 1
/dev/hda5               /boot                   ext3    defaults        1 2
/dev/fd0                /mnt/floppy             auto    noauto,owner    0 0
none                    /proc                   proc    defaults        0 0
none                    /dev/shm                tmpfs   defaults        0 0
none                    /dev/pts                devpts  gid=5,mode=620  0 0
/dev/hda7               swap                    swap    defaults        0 0
/usr/swap0              swap                    swap    defaults        0 0
/dev/sda1               /usb1                   vfat    defaults,user,noauto    0       0
/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0

Unmount hda6 and mount hda5 instead:
[root@fanta workingdir]# cd ~
[root@fanta ~]# umount /dev/hda6
[root@fanta ~]# mount /dev/hda5 /mnt/workingdir
[root@fanta ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda2              27G  1.9G   23G   8% /
/dev/hda1              99M  5.2M   89M   6% /boot
/dev/shm              252M     0  252M   0% /dev/shm
//fanta/backups        30G   24G  5.9G  80% /mnt/fanta/backups
/dev/hda5              99M   17M   78M  18% /mnt/workingdir

Make a backup copy of grub.conf on hda1:
[root@fanta ~]# cp cp /boot/grub/grub.conf /boot/grub/grub.conf.back

Copy grub.conf from the restored boot partition on hda5 to the boot partition currently in
use on hda1.
[root@fanta ~]# cp /mnt/workingdir/grub/grub.conf /boot/grub/grub.conf
cp: overwrite `/boot/grub/grub.conf'? yes
[root@fanta ~]#

Take a look at grub.conf.
[root@fanta ~]#  more /boot/grub/grub.conf
# 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,1)
#          kernel /vmlinuz-version ro root=/dev/hda6
#          initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,1)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-43.9.legacy)
        root (hd0,1)
        kernel /vmlinuz-2.4.20-43.9.legacy ro root=LABEL=/
        initrd /initrd-2.4.20-43.9.legacy.img
title Red Hat Linux (2.4.20-42.9.legacy)
        root (hd0,1)
        kernel /vmlinuz-2.4.20-42.9.legacy ro root=LABEL=/
        initrd /initrd-2.4.20-42.9.legacy.img
title Red Hat Linux (2.4.20-37.9.legacy)
        root (hd0,1)
        kernel /vmlinuz-2.4.20-37.9.legacy ro root=LABEL=/
        initrd /initrd-2.4.20-37.9.legacy.img

Edit grub.conf to point to the new boot partition on hda5 by changing (hd0,1) everywhere to (hd0,4):

[root@fanta ~]# vi /boot/grub/grub.conf
[root@fanta ~]# more /boot/grub/grub.conf
# 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,4)
#          kernel /vmlinuz-version ro root=/dev/hda6
#          initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,4)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-43.9.legacy)
        root (hd0,4)
        kernel /vmlinuz-2.4.20-43.9.legacy ro root=LABEL=/
        initrd /initrd-2.4.20-43.9.legacy.img
title Red Hat Linux (2.4.20-42.9.legacy)
        root (hd0,4)
        kernel /vmlinuz-2.4.20-42.9.legacy ro root=LABEL=/
        initrd /initrd-2.4.20-42.9.legacy.img
title Red Hat Linux (2.4.20-37.9.legacy)
        root (hd0,4)
        kernel /vmlinuz-2.4.20-37.9.legacy ro root=LABEL=/
        initrd /initrd-2.4.20-37.9.legacy.img

Now reboot:
[root@fanta ~]# reboot