Using rsync to Backup Data

The rsync command will create an exact copy of your information in a new location based on what has changed. It takes a look a timestamps to determine what file have changed. This synchronization process is a reliable way to keep two directories exactly the same.

The Trailing Slash
It is important to understand the difference in use with or without the trailing slash.

rsync -av /home/office/ /bk
This example does not move the office directory folder only the contents.

rsync -av /home/office /bk
This example will result in the office directory located under the /bk = /bk/office.

Note the differences and choose the method you want to use for your backups.

Compression
If you want to make your transfer smaller then use the -z option to compress your transfer.

rsync -avz /home/office/ /bk

Archive Mode -a
This will ensure that all symbolic links, devices, attributes,permissions, ownerships,etc. are preservered and transferred. This is the same as rlptgoD

Create an exclude file.
If you have a number of extensions you want to exclude, create a file and then tell rsync where the file is so that these extensions or patterns will not be transferred.

rsync -avz –exclude-from=/home/office/exclude –stats /home/office/ /bk
Here the file containing the patterns is listed by using –exclude-from= followed by a path to the file. As you can see the patterns in the file are not transferred.