Backup & Restore Ext 2/3/4 File Systems

Hi All,

In this article we are going to see how to back and restore Ext 2/3/4 File systems.

All data must be backed up before attempting any kind of restore operation. Data backups should be made on a regular basis. In addition to data, there is configuration information that should be saved, including /etc/fstab and the output of fd i sk -l . Running an sosreport/sysreport will capture this information and is strongly recommended.

# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot1 /boot ext3 defaults 1 2

LABEL=/data /data ext3 defaults 0 0
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=SWAP-sda5 swap swap defaults 0 0
/dev/sda6 /backup-files ext3 defaults 0 0
# fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1925 15358140 83 Linux
/dev/sda3 1926 3200 10241437+ 83 Linux
/dev/sda4 3201 4864 13366080 5 Extended
/dev/sda5 3201 3391 1534176 82 Linux swap /
Solaris
/dev/sda6 3392 4864 11831841 83 Linux

In this example, we will use the /d ev/sd a6 partition to save backup files, and we assume
that /d ev/sd a6 is mounted on /backup-fi l es.
2. If the partition being backed up is an operating system partition, bootup your system into
Single User Mode. This step is not necessary for normal data partitions.
3. Use “dump” to backup the contents of the partitions:

# dump -0uf /backup-files/sda1.dump /dev/sda1
# dump -0uf /backup-files/sda2.dump /dev/sda2
# dump -0uf /backup-files/sda3.dump /dev/sda3

If you want to do a remote backup, you can use both ssh or configure a non-password login.

 

# dump -0u -f – /dev/sda1 | ssh root@ remoteserver.example.com dd
of=/tmp/sda1.dump

 

 Restoration:

Procedures :

1. If you are restoring an operating system partition, bootup your system into Rescue Mode.
This step is not required for ordinary data partitions.
2. Rebuild sda1/sda2/sda3/sda4/sda5 by using the fd isk command.

3. Format the destination partitions by using the mkfs command, as shown below.

 

# mkfs.ext3 /dev/sda1
# mkfs.ext3 /dev/sda2
# mkfs.ext3 /dev/sda3

4. If creating new partitions, re-label all the partitions so they match the fstab file. This step is
not required if the partitions are not being recreated.

# e2label /dev/sda1 /boot1
# e2label /dev/sda2 /
# e2label /dev/sda3 /data
# mkswap -L SWAP-sda5 /dev/sda5

5. Prepare the working directories.

# mkdir /mnt/sda1
# mount -t ext3 /dev/sda1 /mnt/sda1
# mkdir /mnt/sda2
# mount -t ext3 /dev/sda2 /mnt/sda2
# mkdir /mnt/sda3
# mount -t ext3 /dev/sda3 /mnt/sda3
# mkdir /backup-files
# mount -t ext3 /dev/sda6 /backup-files

6. Restore the data.

# cd /mnt/sda1
# restore -rf /backup-files/sda1.dump
# cd /mnt/sda2
# restore -rf /backup-files/sda2.dump
# cd /mnt/sda3
# restore -rf /backup-files/sda3.dump

If you want to restore from a remote host or restore from a backup file on a remote host you can use either ssh or rsh. You will need to configure a password-less login for the following examples:
Login into 10.0.0.87, and restore sda1 from local sda1.dump file:

# ssh 10.0.0.87 “cd /mnt/sda1 & & cat /backup-files/sda1.dump |
restore -rf -“

Login into 10.0.0.87, and restore sda1 from a remote 10.66.0.124 sda1.dump file:

# ssh 10.0.0.87 “cd /mnt/sda1 & & RSH=/usr/bin/ssh restore -r -f
10.66.0.124:/tmp/sda1.dump”

7. Reboot.⁠

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s