How to use rsync to backup files in Linux

Great article on using rsync in linux:

There are two types of backups that I do. The first is a backup of
several key folders, not my entire system. This is in case I blow
something away, or lose some data that I’d want to get back quickly.

I use the rsync command for this. Rsync is a simple and
fast way to make an exact copy of something. That something can be a
single file or a whole file system.

Now my external hard drive is a firewire drive, which Ubuntu
thoughfully mounts in /media for me with the wonderful name of
‘ieee1394disk’. That’s where I want to keep this backup copy. Let’s
open up a terminal session and go backup some stuff.

cd /media/ieee*

Now I’m in my external drive. If you have a USB disk, chances are it’s under /media/usbdisk or /media/whatevertheheckyoucalledit. I’m going to make a folder to store this backup in because I’m something of a filesystem neat freak.

mkdir arsgeek_backup

cd arsgeek_backup

Now there are four directories that I back up on a regular basis. These are my /home directory, my /etc directory my /opt directory and my mp3 collection. )
My mp3’s are located on a FAT32 partition mounted in /media/sda5 in a
folder called music. So here’s the command I use to copy all of these.

rsync -arvu /home /etc /opt /media/sda5/music .

Here’s what the switches after the rsync command mean. a= archive, r= recursive, v= verbose, u= update and z= compress.

What I like about this is that while the first rsync does take some
time to copy all of these files and folders the first time it’s run,
the next time it’s run it only adds new stuff. So if I run this once a
week and the only changes that were made was that I added several new
mp3s to my music directory, it will only copy those new files.

If I accidentally deleted an mp3 that I wanted, I could easily (and
through the GUI) go to my external drive and copy it back. Or if I
accidentally deleted my /home directory (yikes!) I could rsync it back
by reversing the command:

cd /home

rsync -arvu /media/iee*/arsgeek_backup/home .

Technorati Tags: , , , , , ,

Advertisements

5 responses to “How to use rsync to backup files in Linux

  1. Very helpful as I am learning to use rsync. And thanks for citing the website source, something people don’t do enough of these days!

  2. Thanks it was very useful

  3. Thanks for the simple tip. Yours is the final site I was checking before giving up totally with rsync and using some other tool.

  4. Pingback: Using rsync As An Incremental Backup Tool :Bernie’s Ramblings

  5. I dont think you need the switch for recursion and a is the same as -rlptgoD

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s