Backup your Linux box with rsync

Jack Wallen
Oct 11, 2009
Updated • Nov 28, 2012
Backup, Network

In this Linux backup series we have taken a look at Flyback ("Quick and easy backups with Flyback"), Backerupper ("Simple gui backup tool Backerupper"), and Back In Time ("Linux Back In Time: Backup made easy"). But what Linux series would be complete without a command line entry? Not this one.

There is one thing that most Linux backup tools have in common and that is their underlying technologies. In most cases one of the tools that make the GUI backup tools possible is the venerable rsync. Rsync is an incredibly fast and lightweight file copy tool that can not only copy files to and from a local machine, it can also copy over a network connection - which makes rsync an ideal candidate for user-generated backup scripts or cron jobs.

In this tutorial you will learn how easy it is to use rysnc to not only back up specified directories to an external usb drive, but also to backup over a network connection via ssh.

Command structure

The structure of the rsync command is:


Where SOURCE is the location of the directory to be backed up and DESTINATION is where the backup will be placed.

Now the structure of the command changes when you are employing a network facility such as ssh. At that point the command structure would look like:

rsync [OPTIONS] ssh SOURCE user@destination:/directory

Where user is the user name on the remote machine, destination would be either an IP address or domain, and /directory is the explicit path to the directory you want to back up to.


For the first example we are going to backup the directory /home/jlwallen/Documents to the directory /media/disk/BACKUPS. This destination is a directory located on an external USB drive obviously mounted to /media/disk. The command for this backup will be:

rsync -avh /home/jlwallen/Documents /media/disk/BACKUPS

This is where we run into our first "gotcha". What happens with the above command is that any subdirectory in /home/jlwallen/Documents will be created on /media/disk/BACKUPS. So if you want to create a similar directory structure on the destination you should first create a parent directory similar to that of the source. So before you run the rsync command issue this command:

mkdir /media/disk/BACKUPS/Documents

The new rsync command would be:

rsync -avh /home/jlwallen/Documents /media/disk/BACKUPS/Documents

The options used in the above command are:

  • a: Archive mode
  • v: Verbose mode
  • h: Output in human readable format.

Now let's backup the same source to a remote location with the help of secure shell. It will help your cause to first make sure you can log into the remove machine via ssh. Once you have that working you are ready to backup. Using our same example we are going to backup to user jlwallen at the IP address to the directory /home/jlwallen/BACKUPS/Documents. To do this the command would look like:

rsync -avhe ssh /home/jlwallen/Documents [email protected]:/home/jlwallen/BACKUPS/Documents

The added option is e which allows you to specify the remote shell to use.

You will be prompted for the remote users' password and then the coping will begin. But what if you don't want to have to use a password? If you are wanting to set up automated, remote backups you will have to allow this process to happen without entering a password. To do this you have to create an SSH key without a password. Here are the steps for this:

create an ssh key on the source machine with the command:

ssh-keygen -t dsa

Press enter when prompted for a password.

Once the key is created copy that key to the destination key with the following command:

ssh-copy-id -i .ssh/ username@destination

Where username is the user on the remote machine and destination is the IP or domain of the remote machine.

Now rsync copying can be done without having to enter a password.

Final thoughts

The nice thing about this setup is you can now use rsync to create a cron job for backup automation. Rsync is an incredibly flexible and reliable means for backing up your directories and files. It should be since it is the foundation that so many other backup tools were based on.


Tutorials & Tips

Previous Post: «
Next Post: «


  1. Claude LaFrenière said on September 14, 2012 at 5:52 pm

    Hi Martin Brinkmann :)

    In my Windows 7 this is already done in the Task Scheduler by the default installation… The command line is:

    %windir%\system32\rundll32.exe /d srrstr.dll,ExecuteScheduledSPPCreation


    1. Martin Brinkmann said on September 14, 2012 at 6:22 pm

      Thanks for posting that, easier than my way. Have not tried it yet though but will. Wonder why I do not have it.

    2. ilev said on September 14, 2012 at 8:31 pm

      I have it as well but it was configured to run only when the PC is idle.

      Task Scheduler > Task Scheduler Library > Microsoft > Windows > System Restore.
      There are 2 triggers : at 00:00 every day, at startup.

      1. Rich said on September 15, 2012 at 4:07 am

        Much easier and simpler method is at Registry Backup. It runs at startup and invokes VSS to copy registry and keeps last 30 days for restores. Can be invoked within MSFT Recovery Console so better suited to non-boot situations. No authority issues either.

  2. Michael said on September 16, 2012 at 4:57 am

    My task scheduler is also configured this way. But it doesn’t work. My system does NOT make a restore point every time it boots. Its typically not running at midnight.

  3. Achilles Khalil said on September 16, 2012 at 6:57 am

    Hi this is achilles Seo Expert and website designer and developer. I am here to tell you if need help or need any seo expert contact me I can design any kind of site for any country and Optimize with search engin also can bring your site at TOP. Please feel free to contact me. Whoever your work is great awesome. Be Happy.

  4. Frantic said on September 16, 2012 at 10:33 pm

    How is this done in Windows XP, I wonder?

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.