I mentioned earlier in one of my posts on the importance of backing up.Im sure everybody knows how precious data is.So here's how you can backup easily and quickly in linux.
In this case we are using the rsync program.Its a brilliant program, very easy to use and very effecient. The commands too are very simple to remember.First make sure that you have rsync installed.go to the terminal and type

sudo apt-get install rsync

In this tutorial i'll show you how to backup your home folder(/home/user) to your external usb drive or any other drive.I have most of my important data in the home folder itself.So i make it a point to backup the home folder.So i will be backing this home folder to an external usb drive(/media/backupdrive).So the command to backup will be

rsync -av /home/user /media/backupdrive/

You would need to replace user with your username and backupdrive with the name of your backup drive.It may take about an hour or two to backup during the first time, this depends on how much data you have in your home folder.In my case it took around 1.5 hrs for the first time and only around 2 minutes afterwards.As it only copies new files and modified files after the first backup.
Now you can type this command manually everytime.It would work.. an easier way is to do this is save it to a txt file and execute it.Here's how you do it.
After you have tweaked the above command according to your setup.Open a text editor and insert the command in there and save it to a file say backup.txt and place it in your home folder(/home/user).Then make it executable by right clicking on the file and clicking on properties and checking "Allow executing file as a program" in the Permissions tab.This will do the trick.So next time you want to backup.. All you need to do is go to the terminal and type

sh backup.txt

and backup process will start..If you want to schedule this you can do so.I have scheduled this to run every day at 1am . I'm using cron for this.Its a program which can be used to schedule tasks to run automatically.
Here's how you add a cron task .Go to the terminal and type crontab -e .Now add the following line to make schedule it to run at 1am everyday

00 1 * * * sh backup.txt

If you notice its in the following format
Minute,Hour,Day of month,month,day of week
* = All of them , therefore * is being used for day of month,month,day of week.Hence it runs daily.If you want it to run at a specific day , then you need to change the command like this

00 1 * * 6 sh backup.txt

This command would backup the home folder on saturdays only.You can change accordingly..If you see the topmost line of the crontab -e file.You will notice this line

# m h dom mon dow user command

this is what all those things mean:

field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)

The asterisk * means "all of them."

Hope this makes it clear on how crontab works!!!Thats it, so you dont have to worry about backing up manually.It would do it automatically whenever you wish.I highly recommend doing it using cron and please make it a point to backup regularly!!!
cheers..

1 comments

Anonymous said... @ May 3, 2008 at 12:58 PM

Prashanth can you please provide me ur email id. I have one configuration issue which i would like to dicuss.
tomailsathya@gmail.com

Post a Comment