Linux File Sync Tool-rsync

Source: Internet
Author: User
Tags rsync

Rsync

Rsync is used to synchronize data, often as a copy of data, can be synchronized remotely (similar to SCP), can also be synchronized locally (similar to CP), unlike SCP and CP is rsync also supports incremental copy

Mans rsync
Local:rsync [OPTION ...] Src... [DEST] Access via remote Shell:Pull:rsync [OPTION ...] [[email protected]] Host:src ... [DEST] (copy data from remote machine to local) Push:rsync [OPTION ...] Src... [[email protected]] Host:dest (push local data to remote) Access via rsync daemon:Pull:rsync [OPTION ...] [[email protected]] Host::src ... [DEST] rsync [OPTION ...] rsync://[[email protected]]host[:P ort]/src ...         [DEST] Push:rsync [OPTION ...] Src... [[email protected]] HOST::D est rsync [OPTION ...] SRC ... rsync://[[email protected]]host[:P ort]/destlocal:# rsync-av/root/111//tmp/222/access via remote Example of Shell mode (sshd communication way to connect 192.168.11.190 remote machine IP) # rsync-av 192.168.11.190:/tmp/1.txt/tmp/(remote/tmp/1.txt Copy to native/tmp/) # Rsync-av/tmp/123.txt 192.168.11.190:/tmp/(Local data push to remote) An example of Access via Rsync Daemon (which lets clients connect to it via a listening port) #rsync-av 192.168. 11.190::aminglinux/123/1.txt/tmp/(pull from server to on-premises) #rsync-av/tmp/1.txt 192.168.11.190::aminglinux/123/(from local to server) AmiNglinux is the module name. This syntax shows that Rsync has three ways of working: (1). Synchronization is implemented on the local file system. The command line syntax format is the format of the "Local" segment described above. (2). The local host uses remote shell and remote host communication. The command-line syntax is formatted as the above "Access via remote Shell" segment. (3). The local host connects to Rsync daemon on the remote host over a network socket. The command line syntax format is the format for the above "Access via rsync daemon" segment.
Rsync Common Options
-a 包含-rtplgoD -r 同步目录时要加上,类似cp时的-r选项 -v 同步时显示一些信息,让我们知道同步的过程 -l 保留软连接 -L 加上该选项后,同步软链接时会把源文件给同步 -p 保持文件的权限属性 -o 保持文件的属主 -g 保持文件的属组 -D 保持设备文件信息 -t 保持文件的时间属性 --delete 删除DEST(目标)中SRC(源)没有的文件 --exclude 过滤指定文件,如--exclude “logs”会把文件名包含logs的文件或者目录过滤掉,不同步 -P 显示同步过程,比如速率,比-v更加详细 -u 加上该选项后,如果DEST中的文件比SRC新,则不同步 -z 传输时压缩
rsync Synchronous SSH tunnel mode
演示远程同步,需要两台机器一台 192.168.1.110  (源机器)一台 192.168.1.109  (远程机器)# rsync -avPz 111/  192.168.1.109:/tmp/111/   (把本地111目录下的文件同步到远程机器上111目录)# rsync -avPz 192.168.1.109:/tmp/111/   ./111    现在删除源机器上的111,想从远程机器上同步到源机器完整的写法:# rsync -avPz   111/  [email protected]:/tmp/111/      # rsync -avPz   [email protected]:/tmp/111/   ./111    用户名@在这里可以省略,因为它可以自动识别当前终端的用户,如果是当前登录的是root用户就是root用户,如果是当前登录的是user1那就是user1指定端口同步(遇到对方端口不是22的情况)# rsync -avPz -e "ssh -p 10022" 192.168.1.109:/tmp/111/ ./111   ssh除了22端口还有个端口是10022
Rsync Backend Service mode synchronization
rsync服务的方式同步,它采用的是C/S架构:后台服务的方式,需要写一个配置文件,把配置文件放在etc下,通过一个命令把它启动,它会监听一个端口,然后在客户端跟服务端进行通信1写配置文件vim /etc/rsyncd.conf   这个配置文件的名字可以自定义,但是启动的时候一定要指定这个配置文件,如果把配置文件放在etc下,并且命令为rsync.conf它会自动的加载配置文件,不用我们去指定port=8730     默认是8730可以省略,但是指定其他端口一定要写上log file=/var/log/rsync.log   日志文件pid file=/var/run/rsync.pid   每个进程都有一个pid[aming]        模块名,之前那个格式里的模块名从那里来的,就是从这里定义的path=/tmp/rsync  use chroot=yesmax connections=4   最大连接数read only=yes   只读list=yes      uid=root    以那个用户的身份去同步gid=rootauth users=aming   以那个帐号同步secrets file=/etc/rs.passwd    存密码的文件hosts allow=192.168.1.109    允许那些机器可以连你

Linux File Sync Tool-rsync

Related Article

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.