KB-630164 | How to use rsync to Synchronize Files

KB-630164 | How to use rsync to Synchronize Files

Purpose

To provide a clear and practical procedure for using the rsync utility to synchronize files and directories between local systems and remote hosts, including push and pull operations, while preserving file attributes and optimizing data transfer.

Scope

This article applies to Linux systems where rsync is used to copy and synchronize files or directories locally or between systems over SSH. It covers basic rsync syntax, commonly used options, source and destination path handling, and local, remote push, and remote pull operations.


How to use rsync to Synchronize Files


rsync (Remote Synchronization) is a fast and efficient tool used to copy and synchronize files or directories between local systems or remote hosts. It optimizes data transfer by copying only the portions of files that have changed since the last synchronization, rather than transferring the entire file each time. This approach reduces bandwidth usage and significantly improves synchronization performance.

The rsync syntax is really simple:

rsync [OPTIONS] SOURCE DESTINATION

Options

The following are some of the most useful options to add to the rsync command:

  • -v or --verbose: the verbose flag will display information about the progress of the task.
  • -a or --archive: equals -rlptgoD. The archive flag sets the most common options instead of setting them individually.

The following are the options set with -a that can also be set one by one:

  • -r or --recursive: recurses into directories. Must be used when you need to copy all the contents inside a directory.
  • -l or --links: copies symlinks as symlinks, does not copy the file to which they point to avoiding loopbacks to other directories.
  • -p or --perms: preserves the permission of the file.
  • -t or --times: preserves the original modification timestamps.
  • -g or --group: preserves the files' groups ownership.
  • -o or --owner: preservers the files' owners.
  • -D: preserves the device files and special files. You can use the options --devices and --specials to accomplish this.

Some other options that can be used are:

  • -progress: displays the progress status per file.
  • --max-size=SIZE: avoids transferring files larger than the specified size.
  • --min-size=SIZE: avoids transferring files smaller than the specified size.
Source and destination paths

It is important to take into consideration how the source and destination paths are specified since a slash can change the behavior.

For example, to copy everything inside a directory called in /home into another one called /new/destination/ the correct rsync syntax would be:

Shell
rsync -a /home/ /new/destination

To copy the directory so that a new folder called home is also created in the destination directory the syntax would be:

Shell
rsync -a /home /new/destination

Note that a single slash after /home will change the end result.

Using rsync with a remote host

When having SSH access to a remote host it is possible to use rsync with a really similar syntax. To copy the contents from the /home directory to the /home/new directory in a host called REMOTE_HOST a push operation is needed. The syntax would be:

Shell
rsync -a /home USER@REMOTE_HOST:/home/new

It is possible to retrieve files from a remote host to your local machine using rsync with a pull operation. The syntax is similar as the mentioned above but now the remote host is the source:


Shell
rsync -a USER@REMOTE_HOST:/home/new /home
       

References

                                                                                              
    • Recent Articles

    • KB-630208 | How to use Find and Locate to search for files in Linux

      Purpose To provide Linux administrators and Field Engineers with guidance on using the find and locate utilities to efficiently search for files and directories within a Linux filesystem based on criteria such as name, type, size, timestamps, ...
    • KB-630164 | How to use rsync to Synchronize Files

      Purpose To provide a clear and practical procedure for using the rsync utility to synchronize files and directories between local systems and remote hosts, including push and pull operations, while preserving file attributes and optimizing data ...
    • KB-630107 | How to create a Linux swap file

      Purpose To provide Field Engineers and Linux administrators with a standardized procedure for creating, configuring, and validating a Linux swap file. This procedure helps ensure sufficient virtual memory is available when physical RAM is exhausted ...
    • MSI All-in-One (AIO) PC – Physical Damage Policy for Warranty Claims

      MSI All-in-One (AIO) PC – Physical Damage Policy for Warranty Claims MSI's standard warranty does not cover physical or accidental damage to an All-in-One (AIO) PC. If the damage is determined to be caused by external factors rather than a ...
    • KB 134833 - Troubleshooting NVSM Alert NV-CPU-XX – Unrecoverable CPU Internal Error

      Purpose This document provides a general troubleshooting procedure for the NVIDIA System Management (NVSM) alert NV-CPU-XX, which indicates that a CPU has reported an internal error. The article outlines how to verify whether the alert represents an ...
    • Popular Articles

    • CP Plus Camera and NVR Configuration

      NVR Configuration The CP Plus Pro Series of NVRs have been meticulously designed for providing you with upgraded performance and higher recording quality in your IP video surveillance solution. The robust processor that has been inculcated in this ...
    • KB 775235 - Kerberos Authentication – Overview

      What is Kerberos? Kerberos is a secure authentication method used in our Active Directory (AD) environment (mbuzztech.com). It allows users to: Access multiple systems without re-entering passwords (Single Sign-On – SSO) Log in once Where We Use It ...
    • How to Remove and Reinstall NVIDIA Drivers on Ubuntu

      This article provides step by step guide to completely remove existing NVIDIA drivers and reinstall specific version of the NVIDIA driver on the Ubuntu system Prerequisites Administrative (sudo) access to the Ubuntu system. Internet access to ...
    • KB 692001 - Personal Computers and Servers - Classification and Point of Contact

      We can classify the computers that MBUZZ handles based on their form-factor as below: Tower Workstations, Desktops, Gaming PCs and SFF (Small form factor) PCs fall under this category. These are computers people would use on a desk and rarely move. ...
    • KB 298031 - M.2 SSD Tier List

      The sequential read and write speeds, which are usually the most advertised number, are not a proper benchmark of real-world performance or the quality of an SSD. This article categorizes and tiers SSDs based on factors like the type of NAND flash, ...