Rsync自动协商同步数据

Rsync 命令使用

#rsync -av [源目录] [目标目录]           //归档方式进行全部文件复制

#rsync -aruv [源目录] [目标目录]                //归档方式进行增量复制

#rsync -aruv --delete [源目录] [目标目录]        //增量复制并会删除源目录中被删除的目录或文件,用于切换前的最后一次增量同步

使用nohup 可以将进程放置在后台并记录日志:

nohup >/tmp/rsync-xxxx-xx-xx.log rsync -av [源目录] [目标目录] &

Rsync远程数据同步 :

1. 数据传输目的端配置  rsync,xinetd安装(rsync deamon由xinetd控制)

 #yum install rsync xinetd     #安装

#vi /etc/xinetd.d/rsync    #编辑配置文件,设置开机启动

rsync disable = no   #修改为no

#/etc/init.d/xinetd start   #启动 

2.创建rsyncd.conf配置文件

# vi /etc/rsyncd.conf      #创建配置文件,添加以下代码

 log file = /var/log/rsyncd.log      #日志文件位置,启动rsync后自动产生这个文件

 pidfile = /var/run/rsyncd.pid       #pid文件的存放位置

lock file = /var/run/rsync.lock      #支持max connections参数的锁文件

secrets file = /etc/rsync.passwd    #用户认证配置文件,里面保存用户名称和密码

[ecom]                    #自定义名称

path = /data/EnterpriseApp/WebApplication/        #rsync服务端数据目录路径

comment = ecom

uid = root           #设置rsync运行权限为root

gid = root             #设置rsync运行权限为root

port=873               #默认端口

use chroot = no         #默认为true,修改为no,增加对目录文件软连接的备份

read only = no              #设置rsync服务端文件为读写权限

 list = no                         #不显示rsync服务端资源列表

max connections = 200             #最大连接数

timeout = 600                        #设置超时时间

hosts allow = 192.168.21.129                 #允许进行数据同步的客户端IP地址 

2.1创建用户认证文件

 #vi /etc/rsync.passwd                #配置文件,添加以下内容,和secrets file对应

Root:12345678 

2.2设置文件权限

# chmod 600 /etc/rsyncd.conf          #设置文件所有者读取、写入权限

#chmod 600 /etc/rsync.pass            #设置文件所有者读取、写入权限 

2.3启动rsync

#/etc/init.d/xinetd start              #启动

 #service xinetd stop                    #停止

 #service xinetd restar               t #重新启动

2.4 数据源端配置 

rsync,xinetd安装

#vi /etc/xinetd.d/rsync                 #编辑配置文件,设置开机启动rsync

disable = no                           #修改为no

 #/etc/init.d/xinetd start           #启动 

2.5创建认证密码文件

#vi /etc/passwd.txt

123456                                #密码

chmod 600 /etc/passwd.txt                  #设置文件权限,只设置文件所有者具有读取、写入权限即可

3. 数据同步测试

#rsync -aru /data/EnterpriseApp/WebApplication/ [email protected]::ecom --password-file=/etc/passwd.txt

写入cronjob可以定期执行

你可能感兴趣的:(Rsync自动协商同步数据)