James's Ramblings

rsync

Created: June 05, 2020
rsync [OPTIONS] SOURCE DESTINATION

Notes

  • Incomplete. For reading on man page and Arch wiki necessary.
  • For obscure/advanced commands, read the man page; there are lots of caveats.

Full system back-up

  • --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}

Flags

  • - a: archive mode; equals -rlptgoD. In other words:

    -r: recurse. -l: copy symlinks as symlinks. -p: preserve permissions. -t: preserve modification times. -g: preserve group. -o: preserve owner. -D: preserve device files (requires root) and special files.

  • -H: preserve hard links.

  • -A: preserve ACLS. Activates -p as well.

  • -X: preserve extended attributes.

  • -E: preserve executability.

  • -e ssh: use ssh. Other shells can be used with -e SHELL as well.

  • -c: work out what to sync based on checksum, not mod-time & size.

    Substantially slower.

  • -I: don’t skip files that match size and time.

  • -u

    Skip files that are newer on the receiver. Caveats; read man page. Use with care as -u can cause unintended consequences.

  • -n: dry-run.

  • -v: verbose.

  • -P: -partial and --progress.

    --progress: progress bar. --partial: keep partial transfers rather than deleting them.

  • --partial-dir=DIR: keep partial transfers in a specific directory.

    Ex: --partial-dir=.rsync-partial. May need to be in an exclude rule. See man page. Avoid /tmp and other directors writable by any user.

  • -h: human-readable numbers.

  • i: output a change summary for all updates.

  • z: compress files during the transfer.

  • -R: relative paths. Preserves the full path of the file on the source.

    Ex: if /home/james/stuff is rsynced to /tmp the resulting path would be /tmp/home/james/stuff.

  • --delete: delete extaneous files from destination directories.

    Avoid /* with this option as it doesn’t work as expected. Top-level files are not included.

  • --max-size=SIZE: max size in K, M, or G. 1024K = 1B.

    For decimal use KB, MB, or GB.

  • --min-size=SIZE: min size in K, M, or G. 1024k = 1B.

    For decimal use KB, MB, or GB.

  • list-only: list the files instead of copying.

  • --stats: file transfer stats.

  • --log-file=FILE: logs actions to a file.

  • -4: prefer IPv4.

  • -6

    Prefer IPv6.

  • --noatime

    Do not alter atime when opening source files.

  • --exclude={"DIR1","DIR2",...,"DIRN"}

    Exclude directories. Also see --exclude-from in man; this pulls excludes from a file. include and include-from can be used to override exclude.

  • --info=progress2

    Show overall progress and transfer speed.

  • -x

    Don’t cross a filesystem boundry.

  • --usermap=STRING, --groupmap=STRING

    Map users and groups on the remote and local system. STRING=FROM1:TO1,FROM2:TO2,etc

    Ex: --usermap=0-99:nobody,wayne:admin,*:normal --groupmap=usr:1,1:usr Map UIDs 0-99 to nobody. Map wayne to admin: Map anything not matched so far to normal.

    Requires -o for usermap and -g for groupmap.

  • --chown=USER:GROUP

    Specify user and group for destination files. Not compatible with --usermap and --groupmap. Both USER and GROUP can be left empty. If USER is empty, the colon should be retained.

  • --timeout=TIMEOUT

    Maximum I/O timeout in seconds. Default is 0.

  • -b, --backup

    Rename and retain pre-existing destination files. Caveats for --delete; read man. If not used with --backup-dir

  • --backup-dir=DIR

    For use with -b. Specify a directory that pre-existing destination files are moved to. If --suffix is not used, the files retain their names. Relative paths are relative to DESTINATION.

  • --suffix=SUFFIX

    Override the default suffix. If --backup-dir is not specified, the default suffix is ~/

  • --compare-dest=DIR

    The files in DIR are compared in addition to the files in DESTINATION. If files exist in either destinations, they are ignored. This option can be used multiple times.

    Can be used to make incremental back-ups.