How to Use Rsync to Sync New or Changed/Modified Files in Linux

As a system administrator or Linux power user, you may have probably come across or even on several occasions, used the versatile 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 is exceptionally versatile in that, it can copy locally, to/from a remote shell or remote rsync, it is also remarkably flexible, allowing users to specify any number of files to copy.

Suggested Read: 10 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 is 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 while making backups and beyond in Linux.

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

# rsync options source destination

That 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 only copies new or changed files from a source to destination, when I add a new file into myDocuments directory, this is what happens after running the same command second time:

$ rsync -av Documents/* /tmp/documents

Sync New Updated Files

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

Suggested Read: How to Sync Two Apache Web Servers/Websites Using Rsync

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

$ rsync -aunv Documents/* /tmp/documents

Dry Run Rsync Before Syncing Files

After executing a test run, we can then do away with the -n and 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 as to only sync new files on the local machine, that do not exist on the remote machine, we can include the --ignore-existing option:

$ 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 have 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]:~/all/

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 the rsync man page to discover additionally useful options for advanced usage, as I had mentioned earlier on, rsync is a very powerful and versatile Linux tool and many System Administrator and Linux power users know just how advantageous it is.

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

时间: 2024-10-09 05:17:35

How to Use Rsync to Sync New or Changed/Modified Files in Linux的相关文章

【转载】CentOS 6.3下rsync服务器的安装与配置

一.rsync 简介 Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件,也可以使用 Rsync 同步本地硬盘中的不同目录. Rsync 是用于取代rcp的一个工具,Rsync使用所谓的 “Rsync 算法” 来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快.您可以参考 How Rsync Works A Practical Overview 进一步了解 rsync

2-3-2 rsync+inotify备份同步数据

RSYNC = Remote Sync 远程同步 高效,一定要结合shell 官网:https://rsync.samba.org Author: Andrew Tridgell, Wayne Davison, and others Andrew Tridgell是Samba项目的领导者和主要开发人员,同时还在参与开发rsync\Linux Kernel. 与SCP的比较:scp=无法备份大量数据,类似windows的复制 rsync=边复制 ,边统计,边比较 Rsync特性和优点 可以镜像保存

Rsync文件同步

本章结构 关于rsync 1.一款增量备份工具,remote sync,远程同步,支持本地复制或者与其他SSH.rsync主机同步,官方网站:http://rsync.samba.org/. Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件,也可以使用rsync同步本地硬盘中的不同目录. Rsync是用户取代rcp的一个工具,Rsync使用所谓的"Rsync算法"来使本地和远程两个主机之间的文件达到同步,这个算法只传

linux rsync 远程同步

rsync(Remote Sync) 是一个Unix/linux系统下的文件同步和传输工具.Rsync通过"rsync算法"提供了一个客户机和远程文件服务器的文件同步的快速方法.   工作机制:  在远程同步任务中,负责发起rsync同步操作的客户机称为发起端,而负责响应来自客机的rsync同步操作的服务器称为备份源.在下行同步(下载)中,备份源负责提供文档的原始位置,发起端应对该位置具有读取权限:在上行同步(上传)中,备份源负责提供文档的目标位置,发起端应对该位置具有写入权限. rs

rsync自动同步

Rsync介绍 sync是类unix系统下的数据镜像备份工具--remote sync.一款快速增量备份工具 Remote Sync,远程同步支持本地复制,或者与其他SSH.rsync主机同步. 特性如下: 1,.可以镜像保存整个目录树和文件系统. 2.可以很容易做到保持原来文件的权限.时间.软硬链接等等. 3.无须特殊权限即可安装. 4.快速:第一次同步时 rsync 会复制全部内容,但在下一次只传输修改过的文件.rsync 5.在传输数据的过程中可以实行压缩及解压缩操作,因此可以使用更少的带

rsync + inotify 实时同步数据

简介 Rsync (remote sync)是一款开源.快速,多功能.可实现增量的本地或远程数据镜像同步备份优秀工具.它可通过 LAN/WAN 快速同步多台主机间的文件.rsync 当前由 rsync.samba.org 维护.rsync 使用所谓的"rsync演算法"来使本地和远程主机之间的文件达到同步,该算法只传送两个文件中的不同部分,而不是每次都整份传送,因此速度相当快. 特点:   1.可以镜像保存整个目录树或文件系统:   2.可实现增量同步,既只同步发生变化的数据,因此数据

rsync 使用示例

导读 Rsync(remote sync) 是用于同步某一位置文件和目录到另一位置的有效方法.备份的位置可以在本地服务器或远程服务器.本站之前亦有介绍rsync的安装配置和教程,详看<rsync的安装和配置>一文. rsync特征 速度:第一次的rsync同步源的整个内容目录到目标位置.之后,rsync只传递改变的块或字节到目标位置,使传输非常快. 安全:rsync在传输中允许使用ssh协议加密数据. 更少的带宽:rsync分别在发送和接收端对数据进行压缩和解压缩.所以在使用rsync传输数据

Linux同步镜像备份Rsync

我一哥们最近在搞备份,需要用到rsync.因此,鄙人就简单总结了下rsync,也就有了这篇博文,希望对51的博友们有所帮助! RSYNC简介: Rsync (remote sync)是一款开源.快速,多功能.可实现增量的本地或远程数据镜像同步备份优秀工具.它可通过 LAN/WAN 快速同步多台主机间的文件.Rsync 本来是用以取代rcp 的一个工具,它当前由 Rsync.samba.org 维护.Rsync 使用所谓的"Rsync演算法"来使本地和远程主机之间的文件达到同步,该算法只

Linux下同步工具inotify+rsync使用详解

Linux下同步工具inotify+rsync使用详解 Posted on 2014-12-12 |  In Linux|  9|  Visitors 438 1. rsync 1.1 什么是rsync rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.它使用所谓的"Rsync演算法"来使本地和远程两个主机之间的文件达到同步,这个算法只传送两个文件的不同部分,而不是每次都整份传送,因此速度相当快.所以通常可以作为备份工具来使用. 运行Rsync serve