rsync

来源:互联网 发布:lol网络正常ping高 编辑:程序博客网 时间:2024/05/21 17:29
1.rsync 用法
rsync -av 192.168.32.191::aminglinux/123/1.txt /tmp/
rsync -av  /tmp/1.txt 192.168.32.191::aminglinux/123/

2.rsync 选项
-a:  ==rlptgoD
-v:可视化
-r:目录
-l:软连接,如果软连接所对应的源不存在,就没有什么用处
-L:拷贝源文件
-g:数组
-o:属主
-t:时间
-p:权限
--delete:a 同步到 b,当删除 a 中的老数据的时候,加上这个选项,可以删除 b 的老数据
--exclude:同步的时候排除那些目录
-P:看到拷贝进度
-u:(--update)当 a 拷贝到 b 时,在 b 上的数据如果改变了,那么 a 上的数据会覆盖 b 上的数据,加上这个参数后,a 上的数据就不会覆盖 b 上的数据
-z:压缩

3.rsync 同步之 ssh 隧道方式
rsync -av 192.168.32.191:/tmp/1.txt /tmp/
rsync -av  /tmp/1.txt 192.168.32.191:/tmp/

或者:rsync -avPz root@ip(hostname):/tmp/111/ /tmp/111/
如果 ssh 端口不是 22:
首先 知道ssh 另一个端口,加入这个端口是 10022
rsync -avPz -e "ssh -p 10022" root@ip(hostname):/tmp/111/ /tmp/111/
 
4.rsync 后台服务
# vim /etc/rsyncd.conf  (默认配置文件地址)

port=8730  # 默认端口 873
log file=/var/log/rsync.log
pid file=/var/run/rsync.pid

[aming]  #模块名
path=/tmp/rsync
use chroot=yes  #是否登录用户限定在某个目录下,不让软连接的源文件被拷贝
max connection=4
read only=yes  #登录到当前机子上只读
list=yes
uid=root
gid=root
auth users=aming  #同步的用户及密码
secrets file=/etc/rs.passwd
hosts allow=192.168.11.190

# 此模块任何用户都可以认证,只要是 192.168.11.190 ip 的用户
[aming1]
path=/tmp/rsync123
use chroot=yes  #是否登录用户限定在某个目录下,不让软连接的源文件被拷贝
max connections=4
read only=yes  #登录到当前机子上只读
list=yes
uid=root
gid=root
hosts allow=192.168.11.190 192.168.11.191

设置用户名跟密码为
# vim /etc/rs.passwd
aming:123aaa

修改密码文件权限
chmod 400 /etc/rs.passwd

运行: rsync --daemon 如果不是默认的配置文件路径
rsync --daemon --config=/etc/rsyncd.conf
对方机器不是 873 端口的时候,需要指定 端口
rsync -avzP --port 8730 aming@192.168.11.16::aming/1.txt /tmp/111/

查看模块名:
rsync --port 8730 192.168.11.16::
此处跟 list 有关

--password-file=FILE 选项作用:
# vim /etc/rsync_pass
123

rsync -avzP --port 8730  --password-file=/etc/rsync_pass  aming@192.168.11.16::aming/1.txt /tmp/111/

0 0
原创粉丝点击