Daily operation and maintenance --rsync synchronization tool

rsync command is a remote data synchronization tool through LAN / WAN quickly synchronize files between multiple hosts. rsync so-called "rsync algorithm" to make files between local and remote hosts two synchronized, the algorithm only transmit two different parts of the file, but not always the whole transmission, and therefore very fast.

  • rsync function 
    • As a command to achieve local - remote file synchronization
    • As a service to achieve local - remote file synchronization
  • rsync Features 
    • Mirroring can save an entire directory tree and file system
    • You can keep the original permission (permission, mode), owner, group, time (modification time, modify time), soft and hard links, file acl, file attributes (attributes) information
    • High transmission efficiency, the use of synchronization algorithm, only compare changes
    • Support for anonymous transfers, convenient website mirrors; verification can do to enhance security
  • rsync similar services 
    • sync Sync: flush the file system cache, forcing the modified data blocks written to disk and updates the super block.
    • async asynchronous: the first data into the buffer, and then periodically (typically 30s) is synchronized to the disk.
    • rsync remote synchronization: remote synchronous

rsync -of / etc / passwd /tmp/1.txt

rsync -of /tmp/1.txt 192.168.36.131:/tmp/2.txt 


rsync -of /tmp/1.txt 192.168.188.128:/tmp/2.txt

 rsync format

rsync [OPTION] … SRC   DEST
rsync [OPTION] … SRC [user@]host:DEST rsync [OPTION] … [user@]host:SRC DEST rsync [OPTION] … SRC [user@]host::DEST rsync [OPTION] … [user@]host::SRC DEST 

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 over ssh synchronous mode

Push file:

Pull file:

-e "ssh -p 22" designated ports:

 rsync synchronization through services

 1.编辑配置文件/etc/rsyncd.conf
 2.启动服务rsync --daemon
 3.格式:rsync -av test1/ test@192.168.36.130::test/ 

rsyncd.conf Example:

port=873
log file=/var/log/rsync.log
pid file=/var/run/rsyncd.pid
address=192.168.36.130
[test]
path=/tmp/rsync
use chroot=true
max connections=4
read only=no list=true uid=root gid=root auth users=test secrets file=/etc/rsyncd.passwd hosts allow=192.168.36.131 (多个ip以空格隔开,也可以写ip段:192.168.36.0/24) 

 Detailed profiles rsyncd.conf  

 port:指定在哪个端口启动rsyncd服务,默认是873端口。
 log file:指定日志文件。
 pid file:指定pid文件,这个文件的作用涉及服务的启动、停止等进程管理操作。
 address:指定启动rsyncd服务的IP。假如你的机器有多个IP,就可以指定由其中一个启动rsyncd服务,如果不指定该参数,默认是在全部IP上启动。
 []:指定模块名,里面内容自定义。
 path:指定数据存放的路径。
 use chroot true|false:表示在传输文件前首先chroot到path参数所指定的目录下。这样做的原因是实现额外的安全防护,但缺点是需要以roots权限,并且不能备份指向外部的符号连接所指向的目录文件。默认情况下chroot值为true,如果你的数据当中有软连接文件,阿铭建议你设置成false。 max connections:指定最大的连接数,默认是0,即没有限制。 read only ture|false:如果为true,则不能上传到该模块指定的路径下。 list:表示当用户查询该服务器上的可用模块时,该模块是否被列出,设定为true则列出,false则隐藏。 uid/gid:指定传输文件时以哪个用户/组的身份传输。 auth users:指定传输时要使用的用户名。 secrets file:指定密码文件,该参数连同上面的参数如果不指定,则不使用密码验证。注意该密码文件的权限一定要是600。格式:用户名:密码 hosts allow:表示被允许连接该模块的主机,可以是IP或者网段,如果是多个,中间用空格隔开。 当设置了auth users和secrets file后,客户端连服务端也需要用用户名密码了,若想在命令行中带上密码,可以设定一个密码文件 rsync -avL test@192.168.36.130::test/test1/ /tmp/test8/ --password-file=/etc/pass 其中/etc/pass内容就是一个密码,权限要改为600 

After the port is required to change the designated port --port

Customer-side configuration files can be password without entering a password:

Here the password file format only password

 Transfer from https://my.oschina.net/ccLlinux/blog/1859116

Guess you like

Origin www.cnblogs.com/cangqinglang/p/11969447.html