rsync - bunnyamin/bunnix GitHub Wiki

Rsync

Path

  • A trailing path-separator to a directory begins the path inside the directory, for example only the content of the directory is copied.
  • No trailing path-separator to a directory begins the path with the directory, for example the directory, with its content, is copied.

Backup

Action

-c, --checksum           Compare based on checksum and not mod-time and size.
    --delete             Delete extraneous files from destination dirs.
    --delete-before      Delete before, not during, transfer.
-n, --dry-run            Perform a trial run with no changes made.

Criteria

-a, --archive            Archive mode; equals -Dgloprt, note, no -H,-A,-X.

-D                       Same as --devices and --specials.
    --devices            Preserve device files (super-user only).
    --specials           Preserve special files.
-g, --group              Preserve group.
-l, --links              Copy symlinks as symlinks.
-o, --owner              Preserve owner (super-user only).
-p, --perms              Preserve permissions.
-r, --recursive          Recurse into directories.
-t, --times              Preserve modification times.

-x  --one-file-system    Don't cross filesystem boundaries.

-H, --hard-links         Preserve hard links.
-A, --acls               Preserve ACLs (implies --perms).

-X, --xattrs             Preserve extended attributes.

    --exclude=''         Exactly one path.
    --exclude={'', ...}  Two or more paths.

The --exclude "path" is relative to the source, for example, "--exclude 'tmp/swap' /source/ /mnt/target", refers to "/source/tmp/swap".

Output

-h, --human-readable     Output numbers in a human-readable format.
    --ignore-errors      Delete even if there are I/O errors.
-i, --itemize-changes    Output a change-summary for all updates.
    --out-format=FORMAT  Output updates using the specified FORMAT:
                         * %t = current date time
                         * %i = an itemized list of what is being updated
                         * %M = the last-modified time of the file
                         * %-10l = the length of the file in bytes (-10 is for alignment and precision)
                         * %-100n = the filename (short form; trailing "/" on dir) (-100 is for alignment and precision)
    --progress           Show progress during transfer.
-v, --verbose            Increase verbosity, where "vv" increase verbistity *2.
    --stats              Give some file-transfer stats.
    --info=progress2     Overall progress (not individual files).

Remote

-e, --rsh=COMMAND        Specify the remote shell to use.
    --rsync-path=PROGRAM Specify the rsync to run on remote machine.

With Sudo

In target environment:

  • visudo and add <USER> ALL=(ALL:ALL) NOPASSWD: /usr/bin/rsync
  • Where "user" is the account to login as.

In source environment:

  • rsync ... --rsync-path="sudo rsync" ...

Example

Mirror content of source directory in target directory:

  • Note that all examples have dry-runenabled.

  • Locally rsync -avxHAXn --progress --delete-before /source/ /target

  • Remote rsync -avxHAXn --progress --delete-before -e "ssh -vx -p 49999 -F ~/.ssh/ssh_config -i ~/.ssh/prv/user@host" /source/ user@host:/target

  • Remote sudo rsync -avxHAXn --progress --delete-before -e "ssh -vx -p 49999 -F ~/.ssh/ssh_config -i ~/.ssh/prv/user@host" --rsync-path="sudo /usr/bin/rsync" /source/ user@host:/target

    • Required that rsync is installed both locally and remotely.
    • Required to explicitly provide password for sudo unless sudo is allowed without password.
  • Show progress rsync -avxHAXn --delete-before --info=progress2 /source/ /target

  • Show progress rsync -avxHAXn --delete-before --stats --progress --out-format='[%t] [%i] (Last Modified: %M) (bytes: %-10l) %-100n' /source/ /target

Debug, error, troubleshooting

Event Error Cause Consequence Remedy
SSH rsync sudo: a password is required "Allow members of group sudo to execute any command" in /etc/sudoers Rsync over SSH fails In /etc/sudoers, Comment out #%sudo ALL=(ALL:ALL) ALL
⚠️ **GitHub.com Fallback** ⚠️