Create Backup and Restore Linux Server

Backup Your Server's OS
Making a backup of your Linux Operating System is a very simple process that uses tools included in every linux installation.

  1. The first step is to create a location to store the backup. For this article we're going to store the backup on the same hard drive as the installed operating system, but you can attach USB devices like thumb drive and external hard drives and even special storage like iSCSI and NFS mounted device to store the backup.
  2. Once you are logged into the server and at a command line make the directory to store the backup in an organized way such as:
  3. mkdir /backups
  4. Now we will create a compressed version of the Operating System in one single file (tarball) using the tar command.

For RedHat, CentOS and Fedora or any Operating System based on these linux flavors run the following command:

tar cvpzf /backups/backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backups --exclude=/dev --exclude=/sys --exclude=/boot/grub --exclude=/etc/fstab --exclude=/etc/sysconfig/network-scripts/ --exclude=/etc/udev/rules.d/70-persistent-net.rules /

For Debian or Ubuntu run the following command:

tar cvpzf /backups/backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backups --exclude=/dev --exclude=/sys --exclude=/boot/grub --exclude=/etc/fstab --exclude=/etc/network/interfaces --exclude=/etc/udev/rules.d/70-persistent-net.rules /

Once the command completes the tarball will be located at /backups/backup.tgz

***HINT: You can change the name of the tarball file with a date identifier and keep multiple versions or "snapshots" of your server's configuration.

Restore Your Server's OS From a Backup


In order to restore your server from the previously created tarball the server must have the same Operating System version loaded on it. This particular method of backup and restore is not meant for bare metal projects that need to restore an Operating System to an empty hard drive. It was actually designed to move a configured Operating System from one hardware platform to another, but also works well for rolling back an operating system to a previous configuration.

Once you have a working Operating System either on a new hardware platform or the same hardware platform move the tarball to the server you want to restore. If you stored the tarball on a USB device or other external storage just reattach the device and mount it. If the tarball is on another linux server use commands like this to copy it to the new server’s hard drive:

  1. mkdir /backups
    scp root@original_server:/backups/backup.tgz /backups
  2. Of course replace "original_server" with the appropriate IP address.
  3. Enter the root users password and the transfer will begin.
  4. Once the transfer has completed run this command to extract the tarball thereby restoring the Operating System that the tarball contains:
  5. tar xvpfz /backups/backup.tgz -C /
  6. Complete the process with a reboot and troubleshoot any errors that may come up.
  • backup, restore, linuxserver
  • 0 Kunder som kunne bruge dette svar
Hjalp dette svar dig?

Powered by WHMCompleteSolution