Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Having your way with rsync

Sandra Henry-Stocker | March 9, 2016
Maybe you want the directories that you synchronize to be exact copies of each other or maybe you just don't. Let's dig a little more deeply into the rsync command and see if we can't find just the right mix of options for what you want to do.

And then, on the local system, we run rsync again and notice that newfile on the destination server is not overwritten by the file by the same name on the source system.

orig$ rsync -av archive --update sea-aveksa-1:~shs
building file list ... done

sent 163 bytes  received 26 bytes  75.60 bytes/sec
total size is 1176  speedup is 6.22

To ensure that we don't create new files and don't overwrite files that are newer on the destination side, we can combine these two options. Notice in the output shown below that no changes were made.

orig$ rsync -av --update --existing archive sea-aveksa-1:~shs
building file list ... done

sent 157 bytes  received 20 bytes  70.80 bytes/sec
total size is 1176  speedup is 6.64

Excluding content

We can also exclude portions of a directory that you don't want copied from one system (or file system location) to another by using the --exclude option. An example of --exclude is shown in the command below.

$ rsync -aAXv --exclude 'junk' upgrade /backups/

We can exclude multiple directories with just a little more effort. The command below excludes both the junk directory and one called "notes". The paths are relative to the current directory.

rsync -aAXv --exclude={'upgrade/junk/*','upgrade/notes/*'} upgrade /tmp/

Because we included the /* after each of the directories to be excluded, the directories themselves are replicated, but not their content.

When in doubt, check it out

Whenever you're struggling to get the syntax right on an rsync command that is at all complex, remember that you can try out the command without actually making any changes by using the --dry-run option along with -v (verbose). This will show you what rsync would be doing if you ran the command for real, but won't actually replicate anything.


Previous Page  1  2  3 

Sign up for CIO Asia eNewsletters.