Skip to content

Instantly share code, notes, and snippets.

@Koasing
Last active May 30, 2018 05:23
Show Gist options
  • Save Koasing/18bd976cf0767cfc870e0910ddbbbc14 to your computer and use it in GitHub Desktop.
Save Koasing/18bd976cf0767cfc870e0910ddbbbc14 to your computer and use it in GitHub Desktop.
Rsync for NAS beginner

Rsync for NAS beginner

Local backup

rsync -ahvP [-c] [-m] [-W] [-n] [--remove-source-files] [--log-file=FILE] src dest

use sudo to keep file ownership!

recommended options

  • -a : archive mode; equals -rlptgoD (no -H,-A,-X)
  • -h : output numbers in a human-readable format
  • -v : increase verbosity
  • -P : same as --partial --progress
    • --partial : keep partially transferred files
    • --progress : show progress during transfer

use by your decision

  • -c : skip based on checksum, not mod-time & size
  • -m : prune empty directory chains from file-list
  • -W : copy files whole (w/o delta-xfer algorithm)
  • -n : perform a trial run with no changes made (dry-run)
  • --remove-source-files : sender removes synchronized files (non-dir)
  • --log-file=FILE : log what we're doing to the specified FILE

archive mode (-a)

archive mode handles recursion, file ownership, permission and so on...

  • -r : recurse into directories
  • -l : copy symlinks as symlinks
  • -p : preserve permissions
  • -t : preserve modification times
  • -g : preserve group
  • -o : preserve owner (super-user only)
  • -D : same as --devices --specials
    • --devices : preserve device files (super-user only)
    • --specials : preserve special files

archive mode does not handles

  • -H : preserve hard links
  • -A : preserve ACLs (implies -p)
  • -X : preserve extended attributes

additional command

find . -depth -type d -empty -delete

prunes empty subdirectories (useful with --remove-source-files)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment