Skip to main content

Linux rsync Command Examples

Local folder sync

rsync -azP /source/ /destination/

Folder sync over SSH

rsync -e ssh -azP /source/ root@hostname:/destination/

Folder sync over SSH using SSH Private Key

rsync -e "ssh -i /path/to/private/key.pem" -azP /source/ ec2-user@hostname:/destination/

RSYNC options:

-a : Archive mode. It preserves permissions, times, symbolic links, and devices
-z : Compress file data during the transfer
-P : See progress
-r : Recursive copy
-v : Verbose output
-A : Preserve ACL
-X : Preserve extended attributes/SELinux
-H : Backup hard links

Archive mode (-a)

# It Includes:

-r: --recursive recurse into directories

-l: --links copy symlinks as symlinks

-p: --perms preserve permissions

-t: --times preserve modification times

-g: --group preserve group

-o: --owner preserve owner (super-user only)

-D: same as --devices --specials

--devices: preserve device files (super-user only)

--specials: preserve special files


# It excludes:

-A: --acls preserve ACLs (implies -p)

-X: --xattrs preserve extended attributes

-H: --hard-links preserve hard links

References:

  1. tar and rsync: Archive and Preserve SELinux Contexts, Extended Attributes, And ACLs
  2. rsync examples: Backing up data using rsync command
  3. Linux rsync command