Skip to content
Marcel Schmalzl edited this page Jul 22, 2024 · 11 revisions

Sync and/or backup files. This is also very useful if you need to copy/update in increments and have automatic checks about the diff.

Interesting options

rsync will only delete files in the backup folder if and only if --delete is stated!

  • -a: archive mode = shortcut for:
    • --recursive
    • --links (cp symlinks)
    • --perms (preserve permissions)
    • --group (preserve group)
    • --owner (preserve owner, su only)
    • --devices
    • --specials
    • -A/--acls (preserve ACLs)
    • -X/--xattrs (preserve extended attributes)
    • -a excludes --hard-links (preserve hard links)
  • -c: compare based on checksum (not mod-time & size)
  • -A: preseve access control lists (Linux permission management) (--acls)
  • -X: preserve extended attributes (--xattrs)
  • -v: verbose output (--verbose)
  • -P: progress (--progress)
  • -t: preserve modification times (--times)
  • `--include "filePattern"
    • Example for recursive pattern: --include "somePath**"
  • `--exclude "filePattern"
    • You can --include some area of interest and --exclude "*" everything else (note that the order is important)
  • Compression
    • -z: Enable compression
    • --zc=lz4 [opt]: Compression choice/algorithm; rsync --version shows available options
    • --zl=7 [opt]: Compression factor
  • --bwlimit=2000: Limit bandwith to value in kbps (small bursts may occur wich might overshoot); suffixes can be appended like 20m
  • --delete : compare source and backup directory; deletes files in backup directory if those are not present (anymore) in the source directory
  • -u: skip files that are newer on the receiver (--update)
  • -W, --whole-file: do not use the incremental rsync algorithm; the whole file is sent as-is instead. Faster when the bandwidth between source and target machines is higher than the bandwidth to disk (especially when the "disk" is actually a networked file system). This is the default when both the source and target are on the local machine.

Common useful settings

Linux

rsync -acAXvPt "$sourceFolder" "$backupFolder"

Windows (-> NTFS, FAT32 filesystems)

rsync -rlcvPt "$sourceFolder" "$backupFolder"

Timestamping

Add $(date +%Y%m%d) in path for timestamp (ex. outputFile=/var/my-backup-$(date +%Y%m%d).tgz)

Clone this wiki locally