Tested on OpenBSD 6.4 with rsync 3.1.3

Copy files with rsync

Install

# pkg_add rsync-3.1.3
quirks-3.16 signed on 2018-10-12T15:26:25Z
rsync-3.1.3: ok
The following new rcscripts were installed: /etc/rc.d/rsyncd
See rcctl(8) for details.
#

Paths

rync copies src/ to dst and on the second run it does nothing if src/ hasn’t changed. But if run rsync with src (without the trailing slash), it copies src/ to dst/src.

$ mkdir src
$ rsync -r src/ dst
$ find dst
dst
$ rsync -r src/ dst
$ find dst
dst
$ rsync -r src dst
$ find dst
dst
dst/src

Where
-r — recursive

Remember: Add the trailing slash to copy contents of src.

Archive

To create an exact copy of src to dst use -a option:

$ rsync -aH src/ dst
$

Where
-a — archive mode; equals -rlptgoD:
-l — copy symlinks as symlinks
-p — preserve permissions
-ttime
-ggroup
-oowner
-Ddevice and special files
-H — preserve hardlinks

Don’t preserve some attributes

Useful for FAT/exFAT filesystems.

$ rsync -rt --size-only src/ dst
$

Where
-t — preserve modification times
--size-only — skip files that match in size

Verbose output and progress

$ touch src/test
$ rsync -avP src/ dst
sending incremental file list
src/test
              0 100%    0.00kB/s    0:00:00 (xfr#1, to-chk=0/2)

sent 112 bytes  received 36 bytes  296.00 bytes/sec
total size is 0  speedup is 0.00
$

Where
-v — verbose
-P — show progress during transfer

Remote hosts

A source or/and destination can be located on remove hosts. For example, server — is a remove source.

$ rsync -az server:src/ dst
$

Where
-z — compress files during transfer.

Exclude files

$ find src
src/bar
src/bar/foo
src/foo
src/foobar
$ rsync -r --exclude='foo' src/ dst
$ find dst
dst
dst/bar
dst/foobar
$

You can use patterns. For example:

* — match any path, but stop at slashes.
** — anything, including slashes.
? — any character, except a slash.

To delete files from dst that don’t exist in src/ use --delete option and to delete excluded as well use --delete-excluded:

$ rsync -r --exclude='foo*' --delete-excluded src/ dst
$ find dst
dst
dst/bar
$