Use rsync for a simple incremental backup of a folder

rsync is a very useful and powerful program for doing incremental transfers of files, whether that is locally or remotely. It can, however, take a little while to familiarise yourself with how rsync works before you can get started with it however.

In this quick tip, I'll show you how to do a simple incremental local backup of a folder on your system.

So, say I have a folder full of important OpenOffice documents, that I want to backup to my USB memory stick so I have an up-to-date copy of them wherever I go. My source folder here is ~/Documents and my memory stick is mounted at /media/disk right now.

Initially, you will have to use rsync to copy all the files across, since an incremental copy doesn't yet exist. Let's do that now:

$ rsync -avh ~/Documents /media/disk

That sets up an archive copy. Depending on how much stuff you have and where you're copying, it might take some time, but the verbose option we used (-v) should show you the name of each file as it is copied over.

Once that's done, you've got your initial copy done. Now when you need to synchronise the two copies, simply run the same command again. This time, rsync will go off and find only the files that have changed, and copy those over. When it has finished, both copies will then be up-to-date, and you can get back on the move.

This particular method won't delete files from either copy when you delete them from another. Put another way, if I create Document3.odt on my memory stick, then sync back to my computer, but then later delete it from the memory stick, it will remain on my computer.

If you'd prefer both copies to remain completely synchronised, even if that means deleting files from either copy, add the --delete option, like so:

$ rsync --delete -avh ~/Documents /media/disk

Do be careful with that option, however, as you don't want to be deleting things you might need.

That's it for this quick tip!

Avatar for peter Peter Upfold -

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Use rsync for a simple incremental backup of a folder

  1. Duane (guest)

    # Posted on 23 March 2008 at 07:59 PM

    Thank you for the tip. This will be very useful.

  2. Nathan R. Hale (guest)

    # Posted on 23 March 2008 at 08:04 PM

    Sweet tip. Have you tried unison?

  3. Binny V A (guest)

    # Posted on 24 March 2008 at 05:56 PM

    I use rsync for most of my backuping - I even wrote a small script that makes it easy to rsync multiple folders together.

  4. Whit (guest)

    # Posted on 24 March 2008 at 08:43 PM

    Debian testing.....

              From:                     To:

    rsync -av --delete /home/me/ --delete / ^ ^ ^ ^

    The above all on one line will backup your home directory under your username to a backup machine at Make sure you have the "/" at the end of your "from" directory. This makes sure you pick up all the files and directories in the directory /me and then dumps them into the /me directory on the other machine. Be sure to delete your cache and temp files, etc, in your browser and get rid of whatever other files, etc. you don't want brought over to the other machine. The --delete command deletes whatever files and empty directories are on the receiving machine that are not a part of your current backup. So if you want to keep files in the backup that are no longer on your current directory structure, don't use the --delete command as part of your command string. the --delete will cause all files on the backup machine that are not a part of the current backup to be deleted.

    BTW: I believe this command structure depends on a backup directory be made called /backup/home/me on the receiving machine prior to doing the backup. It's been so long since I originated this I don't remember if rsync allows you to make it after you call the command or if it had to be made beforehand. So to cover yourself, make it beforehand and then rsync will dump everything correctly.

  5. Whit (guest)

    # Posted on 24 March 2008 at 08:47 PM

    Note: On the previous post, ignore the lines

    --delete/ ^^^^

    I tried to use them to point out things on the line above them but it did not format correctly when I did my "submit".

    The line above them is correct tho' for what I was describing. Have fun.

  6. # Posted on 25 March 2008 at 01:04 AM

    <strong>Story added...</strong>

    This story has been submitted to! If you think this story should be read by the free software community, come vote it up and discuss it here:

  7. David (guest)

    # Posted on 03 February 2009 at 08:17 PM

    Can anyone please tell me if I can do something like that in windows?

    Thank you

  8. Peter (guest)

    # Posted on 03 February 2009 at 08:21 PM

    There's a version of rsync called <a href="" rel="nofollow">cwRsync</a> available for the Windows platform.

  9. Avinash Reddy Palleti (guest)

    # Posted on 04 February 2010 at 07:40 PM

    hi how can i do incremental backups that is every folder contains changed files with respect to previous backup...and folder name should contain date and time

Home » Articles » Use rsync for a simple incremental backup of a folder