Restore Partitions Using SystemRescueCD and FSArchiver
Partitions cannot be mounted when restoring to them. If services can be stopped that use files on a specific partition, it can be unmounted and restored. However, the root partition can never be restored while the server is online so these instructions will cover the common denominator which requires taking the server offline.
The server needs to be booted up with a CD but not just any CD will do because it needs to have FSArchiver on it. For this document, the ISO image from www.sysresccd.org will be used.
Once downloaded, the ISO can be burned to a CD-ROM disc or uploaded to your ISO repository such as a LUN. VMware and VirtualBox can attach an ISO image and mount it in the CD-ROM device to allow the virtual machine to boot the ISO image.
For this example, files on the root and home partitions will be restored using this summarized procedure:
- Boot the system using the RescueCD.
- Mount the bak partition which contains the backup archives.
- Verify that the backup archives are in good condition.
- Restore the partitions.
- Mount the root and home partitions.
- Verify the restore worked.
- Unmount the partitions.
- Reboot the system.
Be sure the partitions have been backed up and the files are sitting in the /bak volume.
Code:
total 1035280
drwx------ 2 root root 16384 Apr 30 13:31 lost+found
-rw------- 1 root root 156167681 May 3 15:33 srv-ubuntu-boot.fsa
-rw------- 1 root root 59 May 3 15:33 srv-ubuntu-boot.md5
-rw------- 1 root root 747 May 3 15:33 srv-ubuntu-boot.txt
-rw------- 1 root root 11113 May 3 15:40 srv-ubuntu-home.fsa
-rw------- 1 root root 59 May 3 15:40 srv-ubuntu-home.md5
-rw------- 1 root root 749 May 3 15:40 srv-ubuntu-home.txt
-rw------- 1 root root 837941885 May 3 15:38 srv-ubuntu-root.fsa
-rw------- 1 root root 59 May 3 15:38 srv-ubuntu-root.md5
-rw------- 1 root root 750 May 3 15:38 srv-ubuntu-root.txt
-rw------- 1 root root 7142 May 3 15:40 srv-ubuntu-tmp.fsa
-rw------- 1 root root 58 May 3 15:40 srv-ubuntu-tmp.md5
-rw------- 1 root root 745 May 3 15:40 srv-ubuntu-tmp.txt
-rw------- 1 root root 65930756 May 3 15:40 srv-ubuntu-var.fsa
-rw------- 1 root root 58 May 3 15:40 srv-ubuntu-var.md5
-rw------- 1 root root 748 May 3 15:40 srv-ubuntu-var.txt
As a test of the restore, let's delete the two text files created in the previous section:
Code:
rm /important.txt
rm /home/administrator/important.txt
These files should have been included in the backup image. When the restore is complete, these files should return.
Insert the SystemRescueCD CDROM (or mount the ISO image) and boot the server with it.
Here is the 1st screen:
Option #1 was chosen (SystemRescueCd: default boot options)
The next screen takes you to the command prompt:
Show what partitions the system has by using fsarchiver.
root@sysresccd /root % fsarchiver probe simple
Code:
[======DISK======] [=============NAME==============] [====SIZE====] [MAJ] [MIN]
[sda ] [VBOX HARDDISK ] [ 25.00 GB] [ 8] [ 0]
[sr0 ] [CD-ROM ] [ 675.00 MB] [ 11] [ 0]
[=====DEVICE=====] [==FILESYS==] [======LABEL======] [====SIZE====] [MAJ] [MIN]
[loop0 ] [squashfs ] [<unknown> ] [ 620.12 MB] [ 7] [ 0]
[sda1 ] [ext4 ] [boot ] [ 953.00 MB] [ 8] [ 1]
[sda5 ] [LVM2_member] [<unknown> ] [ 24.87 GB] [ 8] [ 5]
[dm-0 ] [ext4 ] [root ] [ 6.00 GB] [254] [ 0]
[dm-1 ] [ext4 ] [var ] [ 3.00 GB] [254] [ 1]
[dm-2 ] [ext4 ] [tmp ] [ 1.00 GB] [254] [ 2]
[dm-3 ] [ext4 ] [bak ] [ 4.00 GB] [254] [ 3]
[dm-4 ] [ext4 ] [home ] [ 1.00 GB] [254] [ 4]
Mount the bak partition which contains the backup archives.
root@sysresccd /root % mkdir /bak
root@sysresccd /root % mount --read-only /dev/dm-3 /bak
root@sysresccd /root % ls -l /bak
Code:
total 1035280
drwx------ 2 root root 16384 Apr 30 13:31 lost+found
-rw------- 1 root root 156167681 May 3 15:33 srv-ubuntu-boot.fsa
-rw------- 1 root root 59 May 3 15:33 srv-ubuntu-boot.md5
-rw------- 1 root root 747 May 3 15:33 srv-ubuntu-boot.txt
-rw------- 1 root root 11113 May 3 15:40 srv-ubuntu-home.fsa
-rw------- 1 root root 59 May 3 15:40 srv-ubuntu-home.md5
-rw------- 1 root root 749 May 3 15:40 srv-ubuntu-home.txt
-rw------- 1 root root 837941885 May 3 15:38 srv-ubuntu-root.fsa
-rw------- 1 root root 59 May 3 15:38 srv-ubuntu-root.md5
-rw------- 1 root root 750 May 3 15:38 srv-ubuntu-root.txt
-rw------- 1 root root 7142 May 3 15:40 srv-ubuntu-tmp.fsa
-rw------- 1 root root 58 May 3 15:40 srv-ubuntu-tmp.md5
-rw------- 1 root root 745 May 3 15:40 srv-ubuntu-tmp.txt
-rw------- 1 root root 65930756 May 3 15:40 srv-ubuntu-var.fsa
-rw------- 1 root root 58 May 3 15:40 srv-ubuntu-var.md5
-rw------- 1 root root 748 May 3 15:40 srv-ubuntu-var.txt
Verify that the backup archives are in good condition:
root@sysresccd /root % md5sum --check /bak/srv-ubuntu-root.md5
Code:
/bak/srv-ubuntu-root.fsa: OK
root@sysresccd /root % md5sum --check /bak/srv-ubuntu-home.md5
Code:
/bak/srv-ubuntu-home.fsa: OK
Restore the root partition:
root@sysresccd /root % fsarchiver restfs --cryptpass="abc123" /bak/srv-ubuntu-root.fsa id=0,dest=/dev/dm-0
Code:
Statistics for filesystem 0
* files successfully processed:....regfiles=96032, directories=19993, symlinks=7266, hardlinks=9, specials=8
* files with errors:...............regfiles=0, directories=0, symlinks=0, hardlinks=0, specials=0
Restore the home partition:
root@sysresccd /root % fsarchiver restfs --cryptpass="abc123" /bak/srv-ubuntu-home.fsa id=0,dest=/dev/dm-4
Code:
Statistics for filesystem 0
* files successfully processed:....regfiles=11, directories=5, symlinks=0, hardlinks=0, specials=0
* files with errors:...............regfiles=0, directories=0, symlinks=0, hardlinks=0, specials=0
Mount the root and home partitions:
root@sysresccd /root % mkdir /mnt/root
root@sysresccd /root % mkdir /mnt/home
root@sysresccd /root % mount --read-only /dev/dm-0 /mnt/root
root@sysresccd /root % mount --read-only /dev/dm-4 /mnt/home
Verify the restore worked:
root@sysresccd /root % ls -l /mnt/root/import*
Code:
-rw-r--r-- 1 root root 0 May 3 17:00 important.txt
root@sysresccd /root % ls -l /mnt/home/administrator/import*
Code:
-rw-r--r-- 1 root root 0 May 3 17:00 important.txt
Unmount the partitions:
root@sysresccd /root % umount /mnt/root
root@sysresccd /root % umount /mnt/home
root@sysresccd /root % umount /bak
Eject the CDROM/ISO and reboot the server.
If it worked right, the server will boot up (we restored the root file system) and the test files should have been restored.
NOTE: If you noticed any ext file systems that had <unknown> labels, you can update them using the tune2fs command which makes identification easier when restoring.
Example 1:
Code:
sudo tune2fs /dev/sda1 -L boot
Example 2:
Code:
sudo tune2fs /dev/dm-0 root
Bookmarks