Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet rsync compares the source and the target and transfers only the differences. The first copy is a full copy; the next runs take seconds. It can keep permissions, owners, times, links, ACLs and SELinux contexts, remove files that are gone in the source, limit the bandwidth and resume interrupted transfers.
Remote paths use user@host:path, like scp; rsync uses SSH by default.
The slash rule : rsync -a src/ dst/ copies the content of src into dst. rsync -a src dst/ copies the folder itself, so you get dst/src/.
Zo schrijf je het rsync [OPTION...] SRC... [DEST]
rsync [OPTION...] SRC... [USER@]HOST:DEST
rsync [OPTION...] [USER@]HOST:SRC... [DEST] Meest gebruikt
Most used -a, --archiveArchive mode: recursive and keep links, permissions, times, group, owner, devices (-rlptgoD). -v, --verboseShow the files that are transferred. -z, --compressCompress data during the transfer. -n, --dry-runShow what would happen, change nothing. -PSame as --partial --progress: show progress and keep half-done files. --deleteDelete files in the target that do not exist in the source. -e, --rsh=command The remote shell, like -e "ssh -p 2222 -i key". -h, --human-readableReadable numbers (K, M, G). --progressShow the progress of each file. --statsPrint statistics at the end. -i, --itemize-changesShow a short code for what changes for each file. -q, --quietShow only errors. What to copy -r, --recursiveGo into folders. -d, --dirsCopy folders without their content. -R, --relativeKeep the full source path in the target. --files-from=file Copy only the names in this file. --exclude=pattern Leave out files that match. --exclude-from=file Read exclude patterns from a file. --include=pattern Do not exclude files that match. --include-from=file Read include patterns from a file. -f, --filter=rule A filter rule (advanced include/exclude). -FRead filter rules from .rsync-filter files. -C, --cvs-excludeLeave out files that version control tools ignore. -x, --one-file-systemDo not cross into other file systems. --existingUpdate only files that already exist in the target. --ignore-existingSkip files that already exist in the target. --max-size=size , --min-size=size Skip files bigger / smaller than SIZE. -m, --prune-empty-dirsDo not create empty folders in the target. -0, --from0Names in --files-from are NUL separated. What to keep -p, --permsKeep permissions. -o, --ownerKeep the owner (root only). -g, --groupKeep the group. -t, --timesKeep modification times. -U, --atimesKeep access times. -N, --crtimesKeep creation times (where supported). -O, --omit-dir-timesDo not keep the times of folders. -J, --omit-link-timesDo not keep the times of links. -l, --linksCopy symbolic links as links. -L, --copy-linksCopy the files that links point to. --copy-unsafe-linksCopy the target of links that point outside the tree. --safe-linksIgnore links that point outside the tree. --munge-linksMake links safe on the receiving side. -k, --copy-dirlinksTreat links to folders as folders. -K, --keep-dirlinksKeep links to folders in the target. -H, --hard-linksKeep hard links. -A, --aclsKeep ACLs (implies -p). -X, --xattrsKeep extended attributes (SELinux contexts are kept with -X). -E, --executabilityKeep the execute bit only. --chmod=mode Change the permissions of transferred files. --chown=user:group Set owner and group of transferred files. --usermap=map , --groupmap=map Map user and group names. --numeric-idsKeep user and group numbers, do not map by name. -DSame as --devices --specials. --devices, --specialsCopy device files / special files (pipes, sockets). --copy-devices, --write-devicesCopy the content of devices / write into devices. -S, --sparseKeep sparse files sparse. --preallocateReserve the space before writing. --super, --fake-superAct as root on the receiver / store privileged attributes as xattrs. Delete and update --delete-before, --delete-during (--del), --delete-delay, --delete-afterWhen to delete extra files in the target. --delete-excludedAlso delete excluded files in the target. --max-delete=n Do not delete more than N files (safety net). --ignore-errorsDelete even when there are I/O errors. --forceDelete non-empty folders when they are replaced by a file. --remove-source-filesDelete the source files after a successful transfer (move). -u, --updateSkip files that are newer in the target. -b, --backupMake backups of files that are replaced or deleted. --backup-dir=dir Put the backups in this folder. --suffix=suffix The backup ending (default ~). --inplaceWrite updates directly into the target file. --append, --append-verifyAdd data to the end of shorter files (and check them). Compare -c, --checksumCompare by checksum, not by size and time (slower, exact). --size-onlyCompare only the size. -I, --ignore-timesDo not skip files with the same size and time. -@, --modify-window=n Times within N seconds count as the same. -W, --whole-fileSend whole files, no delta (faster on fast networks). --checksum-choice=algo The checksum algorithm. --compare-dest=dir , --copy-dest=dir Compare with (or copy from) another folder too. --link-dest=dir Make hard links to unchanged files in this folder (snapshot backups). -y, --fuzzyUse a similar file in the target as a base. Transfer --partialKeep half-transferred files to resume later. --partial-dir=dir Keep half-done files in this folder. --delay-updatesPut all updated files in place at the end. -T, --temp-dir=dir Folder for temporary files. --bwlimit=rate Limit the bandwidth, like 10M. --compress-choice=algo , --compress-level=n Choose the compression and its level. --skip-compress=list Do not compress these file endings. --timeout=sec , --contimeout=sec I/O and connect timeouts. --stop-after=mins , --stop-at=time Stop after some time / at a time. --rsync-path=program The rsync program on the remote side (like "sudo rsync"). -M, --remote-option=opt Send an option only to the remote side. -s, --secluded-argsSend file names safely to the remote side. --fsyncSync each file to disk. --info=flags , --debug=flags Fine control of messages. --list-onlyList the files instead of copying. --port=port , --address=addr , --password-file=file For rsync daemon (rsync://) connections. -4, --ipv4 / -6, --ipv6Use only IPv4 / IPv6. --iconv=spec Convert file name character sets. --write-batch=file , --read-batch=file Save a transfer to a file / apply it elsewhere. -V, --versionShow the version. Niets past bij dit filter.
$ als gewone gebruiker# als root (of met sudo)
1 Sync a folder to a server Kopieer $ rsync -av ~/site/ student@server2:/srv/site/The slash after site/ copies the content. Run it again: only changes are sent.
2 Dry run first, then the real run Kopieer $ rsync -avn --delete /var/www/html/ /backup/html/
$ rsync -av --delete /var/www/html/ /backup/html/Read the list of "deleting" lines before you run without -n.
3 Mirror with deletion Kopieer # rsync -a --delete /etc/ /backup/etc-mirror/The target becomes an exact copy; files removed in /etc are removed in the backup.
4 Use another SSH port and key Kopieer $ rsync -avz -e "ssh -p 2222 -i ~/.ssh/backup_key" /data/ backup@nas:/backups/data/-e passes options to ssh.
5 Keep SELinux contexts and ACLs Kopieer # rsync -aAX /var/www/ server2:/var/www/-A ACLs, -X extended attributes (SELinux labels). Needed for a web server migration.
6 Show progress for big files Kopieer $ rsync -avP rhel-10.iso server2:/srv/iso/If the link drops, run the same command again: it resumes.
7 Leave out files Kopieer $ rsync -av --exclude='*.log' --exclude='.git/' app/ server2:/srv/app/Do not ship logs and git history to production.
8 Daily snapshot backups that use little space Kopieer # rsync -a --delete --link-dest=/backup/2026-10-24 /home/ /backup/2026-10-25/Unchanged files are hard links to yesterday's copy: each day looks full but uses only the changes.
9 Limit the bandwidth Kopieer $ rsync -av --bwlimit=5M /srv/data/ dr-site:/srv/data/About 5 MB/s, so the office network stays usable.
10 Pull files from a server Kopieer $ rsync -av server2:/var/log/httpd/ ./server2-httpd-logs/The remote side can be the source too.
11 Use sudo on the remote side to read root files Kopieer $ rsync -av --rsync-path="sudo rsync" admin@server2:/etc/ ./server2-etc/The remote user needs a sudo rule for rsync.
12 Move files (delete the source after copying) Kopieer $ rsync -av --remove-source-files /var/spool/export/ archive01:/archive/export/Good for files that must leave a server once they are safe elsewhere.
13 Compare two folders by checksum Kopieer $ rsync -avnc /srv/release/ server2:/srv/release/Lists files whose content is different, even if size and time are equal.
14 Safety net for deletions Kopieer # rsync -a --delete --max-delete=50 /data/ /backup/data/If more than 50 files would be deleted (for example the source is empty by mistake), rsync stops.
Niets past bij dit filter.
Let op The trailing slash on the source changes the result. Check with -n first. --delete with the wrong source (an empty or unmounted folder) can wipe the target. Use -n and --max-delete.Normal users cannot keep owners on the target; run as root (or with --rsync-path="sudo rsync") for full system copies. Tips om te onthouden rsync -av src/ dst/ = sync content. -n = test, --delete = mirror, -z = compress, -P = progress/resume, -AX = ACLs and SELinux.