rsync is remote file copy program under Linux. It synchronize file trees across local disks, directories or across a network. It has several advantage over bulky backup software that consume lot of system resources and slow down your pc. rsync uses the remote-update protocol to speed up file transfers when the destination file already exists. The rsync remote-update protocol allows you to transfer differences between two sets of files using an efficient checksum-search algorithm.

rsync Features:

  • support for copying links, devices, owners, groups and permissions
  • exclude and exclude-from options similar to GNU tar
  • a CVS exclude mode for ignoring the same files that CVS would ignore
  • can use any transparent remote shell, including rsh or ssh
  • does not require root privileges
  • pipelining of file transfers to minimize latency costs
  • support for anonymous or authenticated rsync servers (ideal for mirroring)


You need to specify a source and a destination in which one may be remote.

rsync *.php foo:src/

this would transfer all files matching the pattern *.php from the current directory
to the directory src on the machine foo. If any of the files already exist on the remote system then the sync remote-update protocol is used to update the file by sending only the differences.

rsync -avz foo:src/bar /data/tmp

this would recursively transfer all files from the directory src/bar
on the machine foo into the /data/tmp/bar directory on the local machine.
The files are transferred in “archive” mode, which ensures that symbolic links,
devices, attributes, permissions, ownerships etc are preserved in the transfer.

rsync -avz foo:src/bar/ /data/tmp

a trailing slash on the source changes this behavior to transfer all files from the directory src/bar on the machine foo into the /data/tmp/. A trailing / on a source name means “copy the contents of this directory”. Without a trailing slash it means “copy the directory”. This difference becomes particularly important when using the –delete option.


this would list all the anonymous rsync modules available on the host

Available Options

-v, –verbose increase verbosity
-q, –quiet decrease verbosity
-c, –checksum always checksum
-a, –archive archive mode
-r, –recursive recurse into directories
-R, –relative use relative path names
-b, –backup make backups (default ~ suffix)
–backup-dir make backups into this directory
–suffix=SUFFIX override backup suffix
-u, –update update only (don’t overwrite newer files)
-l, –links copy symlinks as symlinks
-L, –copy-links copy the referent of symlinks
–copy-unsafe-links copy links outside the source tree
–safe-links ignore links outside the destination tree
-H, –hard-links preserve hard links
-p, –perms preserve permissions
-o, –owner preserve owner (root only)
-g, –group preserve group
-D, –devices preserve devices (root only)
-t, –times preserve times
-S, –sparse handle sparse files efficiently
-n, –dry-run show what would have been transferred
-W, –whole-file copy whole files, no incremental checks
–no-whole-file turn off –whole-file
-x, –one-file-system don’t cross filesystem boundaries
-B, –block-size=SIZE checksum blocking size (default 700)
-e, –rsh=COMMAND specify rsh replacement
–rsync-path=PATH specify path to rsync on the remote machine
-C, –cvs-exclude auto ignore files in the same way CVS does
–existing only update files that already exist
–ignore-existing ignore files that already exist on the receiving side
–delete delete files that don’t exist on the sending side
–delete-excluded also delete excluded files on the receiving side
–delete-after delete after transferring, not before
–ignore-errors delete even if there are IO errors
–max-delete=NUM don’t delete more than NUM files
–partial keep partially transferred files
–force force deletion of directories even if not empty
–numeric-ids don’t map uid/gid values by user/group name
–timeout=TIME set IO timeout in seconds
-I, –ignore-times don’t exclude files that match length and time
–size-only only use file size when determining if a file should be transferred
–modify-window=NUM Timestamp window (seconds) for file match (default=0)
-T –temp-dir=DIR create temporary files in directory DIR
–compare-dest=DIR also compare destination files relative to DIR
-P equivalent to –partial –progress
-z, –compress compress file data
–exclude=PATTERN exclude files matching PATTERN
–exclude-from=FILE exclude patterns listed in FILE
–include=PATTERN don’t exclude files matching PATTERN
–include-from=FILE don’t exclude patterns listed in FILE
–version print version number
–daemon run as a rsync daemon
–no-detach do not detach from the parent
–address=ADDRESS bind to the specified address
–config=FILE specify alternate rsyncd.conf file
–port=PORT specify alternate rsyncd port number
–blocking-io use blocking IO for the remote shell
–no-blocking-io turn off –blocking-io
–stats give some file transfer stats
–progress show progress during transfer
–log-format=FORMAT log file transfers using specified format
–password-file=FILE get password from FILE
–bwlimit=KBPS limit I/O bandwidth, KBytes per second
–read-batch=PREFIX read batch fileset starting with PREFIX
–write-batch=PREFIX write batch fileset starting with PREFIX
-h, –help show this help screen
Environment Variables

CVSIGNORE : The CVSIGNORE environment variable supplements any ignore patterns in .cvsignore files. See the –cvs-exclude option for more details.

RSYNC_RSH : The RSYNC_RSH environment variable allows you to override the default shell used as the transport for rsync. This can be used instead of the -e option.

RSYNC_PROXY : The RSYNC_PROXY environment variable allows you to redirect your rsync client to use a web proxy when connecting to a rsync daemon. You should set RSYNC_PROXY to a hostname:port pair.

RSYNC_PASSWORD : Setting RSYNC_PASSWORD to the required password allows you to run authenticated rsync connections to a rsync daemon without user intervention. Note that this does not supply a password to a shell transport such as ssh.

USER or LOGNAME : The USER or LOGNAME environment variables are used to determine the default username sent to a rsync server.

HOME : The HOME environment variable is used to find the user’s default .cvsignore file.

Exit Values

RERR_SYNTAX 1 – Syntax or usage error
RERR_PROTOCOL 2 – Protocol incompatibility
RERR_FILESELECT 3 – Errors selecting input/output files, dirs
RERR_UNSUPPORTED 4 – Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was speciifed that is supported by the client and not by the server.
RERR_SOCKETIO 10 – Error in socket IO
RERR_FILEIO 11 – Error in file IO
RERR_STREAMIO 12 – Error in rsync protocol data stream
RERR_MESSAGEIO 13 – Errors with program diagnostics
RERR_IPC 14 – Error in IPC code
RERR_WAITCHILD 21 – Some error returned by waitpid()
RERR_MALLOC 22 – Error allocating core memory buffers
RERR_TIMEOUT 30 – Timeout in data send/receive

Written by Bala Krishna

Bala Krishna is web developer and occasional blogger from Bhopal, MP, India. He like to share idea, issue he face while working with the code.