How to Back Up Linux & Restore on Another Server
Linux is an open-source, Unix-type operating system. Because the Linux kernel, or the core of the operating system, supports a wide variety of hardware, backing up and restoring on another system is supported in any version of the software. Tar is the most basic backup program built into every version of Linux and dates back to tape backup utilities in Unix. Combined with the "dd" command to back up the master boot record (MBR), tar can be used to back up a complete Linux server and restore it on another system.
Instructions
-
-
1
Plug an external drive into the system and mount it. Consult your system manual for specific instructions on mounting the drive. Be sure the external drive has enough space to back up your entire system.
-
2
Open a terminal window and type the following command to copy the MBR:
su -c 'dd if=/dev/sda of=/path/to/externaldrive/sdabk.mbr count=1 bs=512'
Replace "/path/to/externaldrive/" with the path to the external drive. Be sure to include the single quotes in the command.
-
-
3
Type the following command to back up the system:
su -c 'tar -cvpzf /path/to/external/linuxbackup.tgz --exclude=/path/to/external --exclude=/lost+found --exclude=/dev --exclude=/proc --exclude=/sys /'
Replace "/path/to/external/" with the path to your external drive. Enter the command all on one line and exactly as shown. This creates the "linuxbackup.tgz" file on the external drive, which is a full backup of the system. The command excludes the external drive itself and the directories that are dynamically filled by the system at boot time. This command can take a very long time to run, several hours on a system with 20 GB or more of data.
-
4
Un-mount and unplug the external drive from the source system. Consult your system manual for specific un-mounting instructions.
-
5
Plug in and mount the external drive on the new server. Consult your system manual for specific mounting instructions.
-
6
Type the following command on the target server to restore the MBR:
dd if=/path/to/external/sdabk.mbr of=/dev/sda
Replace "/path/to/externaldrive/" with the path to the external drive.
-
7
Type the following command on the target server:
su -c 'tar -xvpzf /path/to/external/linuxbackup.tgz -C /'
Replace "/path/to/external/" with the path to the external drive. Be careful to enter the command on the correct server, because it will completely wipe the system and replace it with the backup.
-
8
Type the following command to create the excluded directories:
su -c 'mkdir /proc && mkdir /lost+found && mkdir /dev && mkdir /sys && init 6'
This recreates the excluded directories and restarts the system. The server is now identical to the original.
-
1