How-to-use Rsync-to-Sync New or changed/modified Files in Linux

Source: Internet
Author: User
Tags rsync

As a system administrator or Linux Power User, your may has probably come across or even on several occasions, used the VE Rsatile Linux Rsync tool, which enables users to expeditiously copy or synchronize files locally and remotely. It is as well a great tool popularly used for backup operations and mirroring.

Some of its eminent features and advantages include; It's exceptionally versatile in, it can copy locally, to/from a remote shell or remote rsync, it's also remarkably Flexible, allowing users to specify any number of files to copy.

suggested Read: practical Examples of Rsync Command in Linux

Furthermore, it permits copying of links, devices, file or directory owner, groups and the permissions. It also supports usage without root privileges coupled with many more.

One imperative differential of rsync in comparison to other file-coying commands in Linux are its use of the Remote-update protocol, to transfer only the difference between files or directory content.

Therefore, in this article, we shall examine how rsync can help us only sync new or changed files or directory content whi Le making backups and beyond in Linux.

To start with, you need remember the conventional and simplest form of using rsync is as follows:

That's said, let us dive into some examples to uncover how the concept above actually works.

Syncing Files locally Using Rsync

Using the command below, am able to copy files from my Documents directory to/tmp/documentsdirectory locally:

$ rsync-av documents/*/tmp/documents

In the command above, the option:

    1. -a–means Archive Mode
    2. -v–means verbose, showing details of ongoing operations

Sync Files Locally

By default, rsync is copies new or changed files from a source to destination, when I add a new file into MyDocuments di Rectory, this is what happens after running the same command second time:

$ rsync-av documents/*/tmp/documents

Sync New Updated Files

As can observe and notice from the output of the command, only the new file was copied to the destination directory.

suggested Read: How to Sync the Apache Web servers/websites Using Rsync

--updatethe or -u option allows rsync to skip files that is still new in the destination directory, and one important op tion, --dry-run or -n enables us to execute a test operation without making any changes. It shows us what files is to be copied.

$ RSYNC-AUNV documents/*/tmp/documents

Dry Run Rsync before Syncing Files

After executing a test run, we can then does away with the and -n perform a real operation:

$ RSYNC-AUV documents/*/tmp/documents

Sync Updated Files

Syncing Files from Local to Remote Linux

In the example below, I am copying files from my local machine to a remote sever with the IP address–10.42.1.5. So-to-only sync new files on the local machine, that does not exist on the remote machine, we can include the --ignore-existing optio N:

$ rsync-av--ignore-existing documents/* [email protected]:~/all/

Sync Files Local to Remote Linux

Subsequently, to sync only updated or modified files on the remote machine that has changed on the local machine, we can Perform a dry run before copying files as below:

$ rsync-av--dry-run--update documents/* [email protected]:~/all/$ rsync-av--update documents/* [email protected]:~/al l/

Check Sync only Updated Files

To update existing files and prevent creation of new files in the destination, we utilize the --existing option.

You can run through rsync man the page to discover additionally useful options for advanced usage, as I had mentioned earlier On, Rsync was a very powerful and versatile Linux tool and many System Administrator and Linux Power users know just how ad Vantageous it is.

Most importantly, you can as well share your view on the examples we had covered here or even better still, offer us valu Able tips on using the vital command line tool through the comment section below.

How-to-use Rsync-to-Sync New or changed/modified Files in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.