This article summarizes some obvious
stuff which is easy to forget (and cause lost time in debugging). So here are some basic + checked concepts I can trust next time I won't understand what's doing on !
file1 file1suffix file2suffix file3it means :
Round description | on the source | on the destination | Comment | ||
---|---|---|---|---|---|
filename | contents | filename | contents | ||
setup | myFile | Hello world |
(doesn't exist yet) | ||
rsync | (no change) | myFile | Hello world |
||
edit | myFile | Hello world edit 1 |
(no change) | ||
rsync --backup --suffix=_BACKUP | (no change) | myFile | Hello world edit 1 |
||
myFile_BACKUP | Hello world |
backup created | |||
edit | myFile | Hello world edit 1 edit 2 |
(no change) | ||
rsync --backup --suffix=_BACKUP | (no change) | myFile | Hello world edit 1 edit 2 |
||
myFile_BACKUP | Hello world edit 1 |
new backup has the same name as the existing backup : overwrite |
Round description | on the source | on the destination | Comment | ||
---|---|---|---|---|---|
filename | contents | filename | contents | ||
setup | myFile | Hello world |
(doesn't exist yet) | ||
rsync | (no change) | myFile | Hello world |
||
edit | myFile | Hello world edit 1 |
(no change) | ||
rsync --backup --suffix=_BACKUP1 | (no change) | myFile | Hello world edit 1 |
||
myFile_BACKUP1 | Hello world |
backup 1 created | |||
edit | myFile | Hello world edit 1 edit 2 |
(no change) | ||
rsync --backup --suffix=_BACKUP2 | (no change) | myFile | Hello world edit 1 edit 2 |
||
myFile_BACKUP2 | Hello world edit 1 |
backup 2 created | |||
myFile_BACKUP1_BACKUP2 | Hello world |
no myFile_BACKUP1 on the destination, so file deleted. Remember ? |
Format of the suffix value | Number of versions kept back |
---|---|
fixed string | 1 |
any string changing at every rsync round | 1 for every round |
quick check(details : man -P 'less -p "quick check"' rsync).
When gathering files in a temporary directory prior to rsync'ing them to receiver (i.e. developing a delivery script), keep in mind that their modification time is the instant they where cp'ed into that temporary directory, even though their content has not changed. Thus, by default, rsync will always consider them as different from those of receiver.
Solution : use the -c or -t flags or cp -p.
Code | Meaning |
---|---|
0 | Success |
1 | Syntax or usage error |
3 | Errors selecting input/output files, dirs |
less -p "^EXIT VALUES"
' rsync
less -p "--no-OPTION$"
' rsync
Flag | Usage |
---|---|
-A --acls | |
-a --archive | archive mode, equivalent to −rlptgoD, i.e. : recursive + preserves (symlinks + permissions + time + group + owner + Devices) |
--backup |
|
--backup-dir=dir | make backups in hierarchy based on dir (default : current directory) |
--bwlimit=n | limit I/O bandwidth to n KBytes per second |
-c --checksum | skip based on checksum, not modification time or size (i.e. if checksums match on both ends, skip file) |
-D | short for --devices --specials |
--delay-updates |
|
--delete | delete files that don't exist on sender
This conflicts with options altering the list of files to synchronize, such as --include-from, --exclude, ...
|
--delete-after | receiver deletes after transfer, not during |
--devices | transfer character and block device files to receiver to recreate these devices. Requires root privileges |
--exclude=pattern | exclude files matching pattern from the list of files to be transferred. Use as many --exclude options as the number of patterns to exclude. |
--exclude-from=file | exclude files matching patterns listed in file |
--files-from=file | read list of source file names from file
|
-g --group | preserve group |
-H --hard-links | preserve hard links |
-I --ignore-times | synchronize everything, skip nothing
This option name is a little puzzling since it suggests that only the file size will be used to skip files, which is not true : files having the same size will be sent anyway. If you actually want to only consider the file size to skip files, consider --size-only.
|
-i --itemize-changes | list the changed files and the cause of each change, coded as an 11-character string. Characters :
less -p "-i, --itemize-changes$" ' rsync
|
--ignore-existing | ignore files that already exist on receiver |
--include-from=file | include files matching patterns listed in file |
-L --copy-links | dereference symlinks (i.e. transform symlink into referent file or directory) |
-l --links | copy symlinks as symlinks |
--modify-window=n -@n | When comparing two timestamps, rsync treats the timestamps as being equal if they differ by no more than the modify-window value :
|
-n --dry-run |
|
-O --omit-dir-times | omit directories from --times |
-o --owner | preserve owner (root only) |
-p --perms | preserve permissions (but not ACL, see --acls) |
--progress | show progress during transfer (for each file) |
-q --quiet | suppress non-error messages |
-R --relative | use Relative path names |
-r --recursive | recurse into directories |
--remove-source-files | sender removes synchronized files (non-dir) |
--size-only | transfer files that have changed in size. This is useful to distinguish files with differenceswhen we can not rely on timestamps (because of mirroring tools / destination filesystem). |
--specials | transfer special files such as named sockets and fifos |
--suffix=suffix | append suffix to backup files name. Defaults :
|
-t --times | preserve times, i.e. transfer modification times along with the files and update them on receiver
If this option is not used (no -t nor -a), the optimization that excludes files that have not been modified cannot be effective, causing all files to be updated again on the next rsync execution.
|
-u --update | update only : don't overwrite newer files |
-v --verbose | verbose mode |
-W --whole-file | copy files whole : disables the incremental algorithm |
-z --compress | compress data
Don't use this on already compressed data (compressed archives, JPEG / MP3 / video / files : that would uselessly eat your CPU and lengthen the whole process.
|
--compress-level=level | set the compression level to use
|
--skip-compress=list | Override the list of file suffixes that will not be compressed
|
/
:/
on the source avoids creating an additional directory level at the destination. This means copy the contents of this directoryas opposed to
copy the directory itself. In both cases the attributes of the containing directory are transferred to the containing directory on the destination.
rsync -av /src/foo /dest rsync -av /src/foo/ /dest/foo