Sunday, November 7, 2010

Ubuntu: How to create full system backup

Since I'm playing around my computer to install iSCSI target and initiator, I needed to create volume groups. That involves partitioning and formatting of my hard drive. Hence I'm very sure this would result in the loss of files from my hard drive :) So I wanted to take full system back up of my Ubuntu. I found a very useful and simple to-do list here. I am going to list those steps here FMR(For My Reference).

The general idea in taking full system back up in Ubuntu(or any Linux for that matter), you can create one compressed archive of all the files with folder structure,then uncompress the archive when you want and viola you have saved your files! Unlike Windows, the creating back up and restoring can be done when the system is running. Warning: while restoring we have to be careful where we uncompress the files to avoid losing data. Here are the steps:

  • Become a root user using "sudo su". Warning: be cautious when you are a super user and execute a command from online, there is a single command which can destroy the entire filesytem!
  • Go to root of the filesystem using "cd /". This would be the place where your back up archive file would be created. Feel free to create the file in remote drives directly.
  • Then use the following single command to create the backup archive
    tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /

    This file would be really big and if you want to use better compression technique, you can also create bzip2 files.
    tar cvpjf backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.bz2 --exclude=/mnt --exclude=/sys /

    This commands take a long time to create the file. The explanation for the command and the options:
    • c- compress, v- verbose, p- preserve permissions
    • backup.tar - filename for the backup file
    • You need to exclude the directories that doesn't contain useful files and the back up file itself. Remove any /mnt if you need to avoid backing up other mounted partitions too.
    • Ignore the error message like "tar: /: file changed as we read it
      tar: Exiting with failure status due to previous errors" which you might get at the end of the process.

  • Restoring:
    The command to restore the file from the same place as root of the filesystem,
     tar xvpfz backup.tgz -C /

    Make sure you create the folders that you excluded from the back up archive. So this would be the list of directories if you had used the above command:
    mkdir proc
    mkdir lost+found
    mkdir mnt
    mkdir sys
    etc...

    Then reboot the system to complete the process.
Thanks to the source: http://ubuntuforums.org/showthread.php?t=35087

No comments: