Filesystem Administration  «Prev 

rsync Command Syntax

The following image contains the syntax for rsync.
rsync parameters
rsync parameters

  1. --verbose --progress --stats
    These options allow you to view the status of the data transfer.
  2. --compress
    This option tells rsync to use compress during the transfer.
  3. --rsh=/usr/local/bin/ssh
    This option tells rsync to use the secure shell to transfer the data and the path to find the ssh utility.
  4. --recursive
    This option tells rsync to follow the source pathname, recursively transferring files that have been added or altered.
  5. --times --perms
    These options preserve the file timestamps and permissions.
  6. /files/*
    /files/* specifies which local filesystem rsync should transfer files from for transmission to the remote rsync server.
  7. fileserver:
    fileserver should be the DNS name or IP address of your rsync server. It is important that you only use one colon to separate the DNS name for the path. Otherwise, rsync will use rsh to perform the transfer instead of ssh.
  8. rsync_server_path_name
    rsync_server_path_name specifies the path the files should be transferred to on the rsync server.

Linux Commands

Synchronize files and folders with rsync

The rsync tool is another way to securely copy files from one system to another. It differs from scp in that if two files or directories are similar between two systems, rsync only needs to copy the differences between the systems, while scp would need to copy everything. One of the advantages of rsync is that it can copy files between a local system and a remote system securely and efficiently. While the initial synchronization of a directory takes about the same time as copying it, any subsequent synchronization only requires the differences to be copied over the network.
One of the most important options of rsync is the -n option to perform a dry run. A dry run is a simulation of what happens when the command really gets executed. It will display the changes to be performed when the command is executed without the dry run option. It is recommended to perform a dry run of any rsync operation to ensure that no important files get overwritten or deleted.

The two most common options when synchronizing files and folders with rsync are the -a and - v options. While the -v option adds verbosity to the output as the synchron ization proceeds, the -a option stands for "archive mode" and enables the following options all in one:
  1. - r: synchronize recursively the whole directory tree
  2. -1: synchronize symbolic links
  3. - p: preserve permissions
  4. - t: preserve time stamps
  5. -g: preserve group ownership
  6. - o: preserve the owner of the files
  7. -D: synchronize device files

While the -a already synchronizes symbolic links, there are additional options necessary to preserve hardlinks, as they are treated as separate files instead. The -H option enables the handling of hardlinks, so the rsync command will identify the hardlinks present in the source folder and link the files accordingly in the destination folder instead of just copying them as separate files.