Rsync
rsync
Fedora/RHEL distribuuje rsync ako tri subpackages: rsync
, rsync-daemon
a rsync-rrsync
. Subpackage rsync-daemon
obsahuje systemd scripts pre spustanie rsync daemon, okrem ineho subor /usr/lib/systemd/system/rsyncd.service, ktory obsahuje ExecStart=/usr/bin/rsync --daemon --no-detach "$OPTIONS"
. Vseobecne sa dnes pouzivanie rsync daemon neodporuca, hlavne kvoli bezpecnosti (spojenie nie je zasifrovane). Na remote transfer moderny rsync pouziva remote shell (ssh by default). Od verzie 3.4.1-3 (released 2025-01) sa python script file rrsync(1)rpm presunul do samostatneho tretieho rsync-rrsync
subpackage.
Okrem rsync(1), ktory je licencovany pod GNU GPL 3, existuje aj openrsync(1) licencovany pod BSD license (a vyvijany OpenBSD komunitou). V macOS od verzie 15.4 (released 2025-03) je rsync symbolicky odkaz na openrsync.
Fedora 42 | RHEL 9.6 | Synology DSM 7.2.2/usr/bin/rsync |
SynoCli Network Tools v2.5/usr/local/bin/rsync
|
---|---|---|---|
3.4.1 (released 2025-01) | 3.2.5 (released 2022-08) | 3.1.2 (released 2015-12) | 3.4.1 (released 2025-01) |
NOTE rsync(1)rpm must be installed on both the source and destination machines. |
rsync finds files that need to be transferred using a "quick check" algorithm (by default) that looks for files that have changed in size or changed in last-modified time. Note that --checksum, -c
option changes this to compare a checksum for each file that has a matching size (but will expend disk I/O reading and CPU, significantly slowly).
When comparing two timestamps (modified times), rsync treats the timestamps as being equal if they differ by no more than the --modify-window=NUM, -@
value. The default is 0, which matches just integer seconds. If you specify a negative value (and the receiver is at least version 3.1.3 (released 2018-01)) then nanoseconds will also be taken into account. Pre modify time (option --times, -t
, resp. --archive, -a
) preneseneho suboru rsync pouziva 8-bytes transfer protocol, t.j. modify time transfer with nanoseconds (full) precision.
rsync uses a delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Note that delta-transfer is disabled for local transfer or --whole-file, -W
option was used, see also [1].
There are two different ways for rsync to contact a remote system: using a remote-shell program as the transport (such as ssh or rsh) or contacting an rsync daemon directly via TCP.
- The remote-shell transport (recommended) is used whenever the source or destination path contains a single colon
:
separator after a host specification. - Contacting an rsync daemon directly (not recommended) happens when the source or destination path contains a double colon
::
separator after a host specification, or when anrsync://
URL is specified.
V pripade ak by sa v nazve suboru vyskytol znak :
resp. ::
, tak rsync skonci pravdepodobne s nejakou chybou.
A trailing slash /
on a source (SRC) path means "copy the contents of this directory". Without a trailing slash it means "copy the directory". Trailing slash /
on the destination (DEST) doesn't matter, except when the source is a file and the destination directory does not exist, see also [2].
dirSRC | rsync -r dirSRC dirDEST |
rsync -r dirSRC/ dirDEST
|
cp -r dirSRC dirDEST |
cp -r dirSRC/ dirDEST
|
dirSRC ├── dirA ├── dirB │ └── fileB1 ├── file1 └── file2 |
dirDEST └── dirSRC ├── dirA ├── dirB │ └── fileB1 ├── file1 └── file2 |
dirDEST ├── dirA ├── dirB │ └── fileB1 ├── file1 └── file2 |
dirDEST ├── dirA ├── dirB │ └── fileB1 ├── file1 └── file2 |
dirDEST ├── dirA ├── dirB │ └── fileB1 ├── file1 └── file2 |
Option -r or --recursive means recursively for both rsync and cp commands
|
rsync nasleduje BSD konvenciu, ktora inak spracovava zadanu cestu s/bez trailing slash /
(napr. BSD cp vs. GNU cp prikazy sa mozu spravat odlisne s/bez trailing slash /
), see also [3], [4], [5]. Fedora/RHEL je GNU system + bash completion pridava trailing slash na konci directories => rsync dirSRC/ dirDEST/
.
At least one source is required. Usages with just one SRC arg and no DEST arg will list the source files (similar to ls -l
) instead of copying, i.a. useful for file listing on remote machine rsync user@remote.host:/opt/
.
Do not confuse option --delete
, i.e. delete extraneous files (cudzie subory) from dest dirs with option --remove-source-files
, i.e. sender removes synchronized files (non-dir). The --remove-source-files
means the rsync command will remove from the sending side the files (non-directories) that are a part of the transfer and have been successfully duplicated on the receiving side. On the other hand, --delete
option tells rsync to delete extraneous files (cudzie subory) from the receiving side (ones that aren’t on the sending side) but only for the directories that are being synchronized. See also [6], [7], [8].
Option --delete
(if none of the --delete-WHEN
options are specified, rsync will choose the --delete-during, --del
algorithm when talking to rsync 3.0.0 or newer) pokial je mozne tak pouzivat vzdy spolu s --backup
resp. --backup-dir
. Staci mala nepozornost a mozeme omylom zmazat potrebne subory, preto vzdy najprv pouzit spolu s option --dry-run, -n
.
Option --filter=RULE, -f add a file filtering RULE. See the FILTER RULES section for detailed information on this option. --exclude=PATTERN
is equivalent to specifying --filter='- PATTERN'
and --include=PATTERN
is equivalent to specifying --filter='+ PATTERN'
. Options --exclude-from=FILE
and --include-from=FILE
allow specifies a FILE that contains exclude/include patterns (one per line). NOTE Rule name "include" is a bit misleading. It might be clearer to call them "don't exclude" rules, or even better "don't exclude even if there's an exclude rule later in the filter list that says to". In other words, think of the "include" pattern as a way of overriding exclude pattern. See also [9], [10] or [11].
Warning The order of the rules is important because the first rule that matches is the one that takes effect, see also [12].
rsync filter rules umoznuju naozaj pokrocili vyber suborov/dirs, napr. [13]. Niekedy vsak moze byt efektivnejsie pouzitie rsync
v kombinacii s find
, napr. [14] (pozor pri hladani dirs vs files v kombinacii s recursive rsync). See also [15], [16] or [17].
Expansion of wildcards on the command-line (e.g. *.c
) into a list of files is handled by the shell before it runs rsync and not by rsync itself (exactly the same as all other Posix-style programs).
rsync --archive, -a mode is -rlptgoD
| |
--recursive, -r |
recurse into directories |
--links, -l |
copy symlinks as symlinks |
--perms, -p |
preserve permissions |
--times, -t |
preserve modification times |
--group, -g |
preserve group |
--owner, -o |
preserve owner (super-user only) |
-D |
same as --devices --specials
|
--devices |
preserve device files (super-user only) |
--specials |
preserve special files |
rsync --archive, -a mode is not -AXUNH
| |
--acls, -A |
preserve ACLs (implies --perms) |
--xattrs, -X |
preserve extended attributes |
--atimes, -U |
preserve access (use) times |
--crtimes, -N |
preserve create times (newness) |
--hard-links, -H |
preserve hard links |
examples
$ rsync --archive --delete --backup --backup-dir="$HOME/BackupDir$(date +_%F_%T)" dirSRC/ dirDEST/ \ --verbose --itemize-changes # --dry-run # NOTE--backup-dir=DIR
implies the--backup
option (from rsync 3.2.1, released 2020-06)
$ rsync dirSRC/ user@remote.host:dirDEST/ # => {home folder of 'user' on 'remote.host'}/dirDEST/ $ rsync file1 user@remote.host: # => {home folder of 'user' on 'remote.host'}/file1 $ rsync file1 user@remote.host:. # => to same as previous
$ rsync --rsh='ssh -v' user@remote.host: $ rsync --rsh='ssh -p 2222' user@remote.host: ssh: connect to host remote.host port 2222: No route to host rsync: connection unexpectedly closed (0 bytes received so far) [Receiver] rsync error: unexplained error (code 255) at io.c(232) [Receiver=3.4.1] $ rsync --rsync-path='/none/rsync' user@remote.host: bash: line 1: /none/rsync: No such file or directory rsync: connection unexpectedly closed (0 bytes received so far) [Receiver] rsync error: error in rsync protocol data stream (code 12) at io.c(232) [Receiver=3.4.1]
# sync last-modified time only (preserve timestamps exactly), see also [18] $ rsync --archive --size-only big.file remote.host: --progress --itemize-changes # try add this --ignore-non-existing, --existing option
# ToDo: resume transfer (after interrupted) by rsync, see also [19], [20], [21], [22] # ToDo options: --partial and --inplace or --append or --append-verify # --inplace implies --partial a udajne (potrebne preverit) --append implies --inplace # Zmysel len pri praci s velmi velkym suborom/subormi a pre remote transfer, resp. aj pre local transfer, ale potom musi byt pouzita option --no-whole-file, --no-W. # Pouzitie --append je rychlejsie (ale nebezpecnejsie) ako --inplace (rozdiel medzi tymito options).
rclone
rclone(1)rpm is a command-line program to manage files on cloud storage (rsync for cloud storage) and supports many cloud storage systems. Configuration file is stored at $HOME/.config/rclone/rclone.conf.
$ rclone sync /home/musinsky/CLOUD_yandex/ yandex_disk: --verbose # --dry-run $ rclone sync yandex_disk: /home/musinsky/CLOUD_yandex/ --verbose # --dry-run
$ rclone about yandex_disk: $ rclone ls yandex_disk:work $ rclone lsl yandex_disk:work $ rclone copy local.file yandex_disk:work
others
https://pairdrop.net/ | GitHub | Local file sharing in your web browser (installation is not required) |
https://localsend.org/ | GitHub | Share files to nearby devices (no rpm package, only Flathub) |