rsync and slashes

Rsync will do things differently based on how you add a slash to the source.

Let's say you have two directories: src and dest, and that src has a file named document.txt in it.

You have two options: Use rsync to copy the entire folder of src with its contents, or copy the contents alone without the folder.

Here's how each would look:

Copy the entire directory:

rsync -r src dest
ls dest/src/document.txt

Copy the contents of the directory:

rsync -r src/ dest
ls dest/document.txt

Use the second example if you want to copy all files, including dot files in the directory.

If you want to ignore the dotfiles, then use an * to exclude those:

touch src/.dotfile.txt
rsync -r src/* dest

Copy files to keep them as close to the original as possible

rsync --archive --times foo:src/bar /data/tmp

Add some options for large transfers

Keep a log of transfers

rsync --log-file=/tmp/rsync.log
Display progress
rsync --progress
Compress as copying files
rsync --compress
Exclude files
rsync --exclude 'foo-bar*'
Exclude files and delete them on the destination
rsync --exclude 'foo-bar*' --delete-excluded
Specify rsync path

When using SSH to connect to a remote server, it will drop the PATH to /bin:/usr/bin by default. If rsync is not in that path, set the path manually:

rsync --rsync-path=/usr/local/bin/rsync