Synchronising local drives using rsync

Just spent a few minutes testing how to synchronise a back up drive on Ubuntu. After reading a few hundred lines of man pages I came up with what I needed. This is just a summary of what I needed to get my backups done.

My 2 directories

Working directory
Backup directory
Here is recursive list of the working directory

d_1_1  file1  file2  file3


To synchronise the d_1 directory now and in the future efficiently

Using rsync


rsync [options] working_directory backup_directory

Some of the rsync Options

Increase verbosity
Recurse into directories
Transfer directories without recursing
Skip files that are newer on the receiver
Dry run
Do not update files at the destination that already exist
Give file transfer stats
Output in human readable format
Show progress during transfer


Lets run the rsync command over d_1 a few times using different flags


rsync -vrn --stats --human-readable --progress d_1/ d_2/


The following is the output to the screen doing a dry run, when the command is run without the dry run option, the two folders are synchronised (even the directory d_1_1 and its file file1_1, as we used the -r option)

sending incremental file list
Number of files: 6
Number of files transferred: 4
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 105
File list generation time: 0.020 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 134
Total bytes received: 28
sent 134 bytes  received 28 bytes  324.00 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)

Further tests

That is a fairly simple example so lets try something a bit more interesting.


Ignore files that already exist

rsync -vn --stats --human-readable progress --ignore-existing d_1/ d_2/

This synchronised d_1 to d_2 however it did not copy over any files that already existed.

Update files that already exist if they are newer

rsync -vun --stats --human-readable --progress d_1/ d_2/

This synchronised d_1 and d_2 and only updated files that had been modified (in the working copy) and therefore were newer than the file in the backup copy (d_2)

Transfer directories without recursing

rsync -vdn --stats --human-readable --progress d_1/ d_2/

This synchronised d_1 to d_2 however directories directly under d_1 were brought across to d_2 minus their contents and any subdirectories were completely ignored.


2 thoughts on “Synchronising local drives using rsync

  1. the –ignore-existing is handy if you have large files. The reason for this is that they are still processed to see if they are different which slows things down. So advice is to use –ignore-existing if you know that the files you are syncing are only new files and not replacments of old files (using the same name)

Leave a Reply

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

You are commenting using your 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