Backup your Linux System
When was the last time you had a copy of your important data? How often do you backup your data?
Last week, while creating a swap partition, I accidentally deleted some of my important documents. Even though I perform a weekly backup of my system, I was not able to retrieve those documents as I did not have any back-up copy of those documents on my computer. Fortunately enough, I had the sense to store my documents in the cloud (in Dropbox ), so no harm done there.
We learn our lesson only when we get the burn. So after going through this post, I hope you will be able to back up your system and get used to it.
Types of Backup
a. Full – back up all the files of the target
b. Incremental – backup all the files that have changed since the last backup.
c. Differential - backup the data changed since last full backup
In this article, I have used TAR ( a CLI backup utility ) and sbackup( a GUI backup utility). Since this article is written on the basis of Ubuntu distribution, this article is based on the GNU version of TAR. It also does not mean that this is only applicable for Ubuntu distributions.
For more information on TAR, refer our previous stone http://www.fortystones.com/40-linux-shell-commands-beginners/ . I highly recommend you to go through manual page of TAR if you have any doubt.
Let us backup our root folder
# tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /
/proc and /sys are virtual filesystems that provide windows into variables of the running kernel, so we exclude them.
/dev is a tmpfs whose contents are created and deleted dynamically by udev, so we exclude it.
Similary, we exclude /lost+found, /mnt, /media
If compression is important to you, use bzip2.
# tar -cvpjf backup.tar.bz2 --exclude=/backup.tar.bz2 --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /
It’s a wise step to create a full backup and then continue with Incremental Backups.
Step 1. Create a full backup
# tar -cvpzf backup1.tar.gz --listed-incremental=/var/log/test.snar /home/rabi/
( backup all the contents of /home/rabi in backup.tar.gz./var/log/test.snar file will be used in our incremental backup. This is a level 0 backup )
Copy this snapshot file /var/log/test.snar for differential backup.
# cp /var/log/test.snar /path/to/test_new.snar
Once you have made a full backup, you don’t need to perform this step again for Incremental Backups.
Step 2. Incremental Backup
# tar -cvpzf backup2.tar.gz --listed-incremental=/var/log/test.snar /home/rabi/
( this is a level 1 backup ).
You can associate tar with find command to backup the files which have changed since the last 24 hrs.
# tar cvf /media/myUSB `find / -mtime -1 -type f -print`
( For more information on find , refer http://www.fortystones.com/master-find-command-linux/ ).
or, you can use the option –newer
# tar -cvf /media/myUSB/backup.tar.gz --newer '10 May 2011' /usr/src
We will be using the snapshot file that we had created before ( in Incremental Backup ) to perform Differential Backups.
# tar -cvpzf backup3.tar.gz --listed-incremental=/path/to/test_new.snar /home/rabi
Splitting the Archive
Now, if you need to split the archive into various files of your desired size, use split command. You can split the archive during creation by removing the f option of tar ( i.e. redirecting the output of the archive to standar output ) and then using the pipe command .
For e.g. to backup my home folder and split the files in the size of 4000 Mb during the archive creation,
$ tar -cvpz --exclude=/home/rabi/backup_home.tar.gz /home/rabi | split -d -b 4000m - /home/rabi/backup_home.tar.gz.
If you have an archive file and you want to split it into several files of your desired size,
$ split -d -b 4000m /path/to/backup.tar.gz /where/tosplit/backup.tar.gz.
To add Date to your splitted files, use
$ split -d -b 4000m /path/to/backup.tar.gz /where/tosplit/backup-`date ' +%d-%B-%Y'`.tar.gz.
Backup Using sbackup ( GUI backup utility )
# sudo apt-get install sbackup
You can also install sbackup from Ubuntu Software Center or Synaptic Package Manager
7 Comments + Add Comment
Leave a comment
- 40 Basic Linux Command-line Tips and Tricks
- Tips and Tricks for Facebook Chat (Save History/ Video Chat/ Send Files)
- 40 Linux Shell Commands for Beginners
- Creating a Simple GUI for Absolute Beginners (Java Tutorials)
- Online Coding Zones for Programmers
- Special: Facebook Smiley, Special Text Symbols and ASCII Arts
- The First on the World Wide Web