Backup any Linux box on SoftLayer

The safest copy is an offline copy. In this article, we’ll cover how to backup entire partitions in Linux systems. It’ll utilize the tar command in Softlayer’s unique rescue environment and showcase the simplicity and flexibility of the process.

We begin by quickly identifying and becoming familiar with our filesystems.

1. Log into your server as the root user type: df -h

Log into your server as the root user type: df -h

2. Take note of the filesystem column and note the / mount has the filesystem /dev/sda2.

This is our root partition. Make note of it as it’ll be needed once our system is in the rescue layer. Our rescue layer is our diagnostic layer where customers can troubleshoot and backup files.

3. Once you are sure you want to make backups of files, initiate the rescue layer. It will not wipe your data but it will reboot your server and unmount your existing partitions.

Follow these steps to initiate the rescue layer:

http://knowledgelayer.softlayer.com/procedure/launch-rescue-kernel

4. After you initiate rescue layer, wait five to six minutes for the rescue layer to finish loading. Then login to the server using SSH. You can find the rescue layer password by going into your Customer Portal (http://control.softlayer.com). Navigate from the Device tab to the Devices List. Select and click on your device name. Click the Passwords tab. Click on the asterisks to reveal your password.

5. Once you’re logged into the rescue layer, you’ll need to mount your partitions.

6. Now mount the root (/) partition in the rescue layer:

    mount /dev/sda2 /mnt

7. Then we’ll need to quickly mount the rest of the partitions under /mnt. You can do this by running the command below:

cat /mnt/etc/fstab | grep UUID | egrep -v ‘swap|/ *ext’ | awk -F= ‘{print $2″ /mnt”$3}’ | awk ‘{print $1″ /mnt”$2}’ | xargs -I {} echo mount -U {}

This results in mount commands to mount the rest of the filesystems. Simple, right? Be sure to save that command; it’ll expedite your rescue layer troubleshooting next time.

This results in mount commands to mount the rest of the filesystems. Simple, right? Be sure to save that command; it'll expedite your rescue layer troubleshooting next time.

8. Triple left-click each line to select the full line, then right-click to paste and run that command to mount each partition.

9. If you want to see all your previously mounted filesystems, we can access them by chrooting as follows: chroot /mnt

  1. Browse to the main folder (aka root folder /):

    cd /

  2. Before we finish, make a backups folder to contain your backups:

    mkdir backups

Now make backups using the tar command in the compressed format tar.gz. To make backups using tar.gz, we’ll make a backup of a very common and important partition: /home

1. Browse to root:

    cd /

2. Run the following

    tar -pzcvf /backups/fullbackup.tar.gz –directory=/home –exclude=backups .

A quick explanation of the flags:

  • -p tells us to preserve file permissions
  • -z tells us to compress the files
  • -c tells us to create the tar.gz file
  • -v gives us visible output
  • -f lets us know the filename we’re working with
  • -directory=/ tells us where the backups should start. Be sure to include the “.” In the tar command as shown above.

It is always recommended that you test your backups to make sure they have the files you need and data’s integrity is preserved. Once you’ve made the backup file, you can reboot the machine and download the file to restore it on another server.

3. To restore that file, upload it via SFTP to your root directory, then in SSH run the following:

    tar -pzxvf fullbackup.tar.gz -C /home

A quick explanation of the flags:  -c /home tells us to first browse to the /home directory and then begin to extract the .tar.gz file. By default, the restoration will overwrite any file with the same name. There are flags such as “–keep-old-files,” which prevent you from replacing existing files on the disk, and “–keep-newer-files” when you don’t want to replace newer existing files, e.g. tar -pzxvf fullbackup.tar.gz -C /home –keep-newer-files.

-Stanley

نوشته های مشابه