10.28 rsync工具介绍ssh
10.29/10.30 rsync经常使用选项工具
10.31 rsync经过ssh同步code
yum install -y rsync
rsync -av /etc/passwd /tmp/1.txt rsync -av /etc/passwd root@192.168.83.22:/tmp/1.txt
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经常使用选项rem
示例:同步
//准备实验用的aaa目录 root@axiang01 ~]# ls -l aaa 总用量 4 -rw-r--r--. 1 root root 12 7月 19 10:13 11.txt drwxr-xr-x. 2 root root 6 7月 19 10:12 aa lrwxrwxrwx. 1 root root 10 7月 19 10:19 softlink1 -> /tmp/1.txt //日思一脑残rsync av是标配 [root@axiang01 ~]# rsync -av /root/aaa/ /tmp/aaa_dest/ 建议目录后加“/” sending incremental file list created directory /tmp/aaa_dest ./ 11.txt softlink1 -> /tmp/1.txt aa/ sent 161 bytes received 41 bytes 404.00 bytes/sec total size is 22 speedup is 0.11 [root@axiang01 ~]# ls -l /tmp/aaa_dest 总用量 4 -rw-r--r--. 1 root root 12 7月 19 10:13 11.txt drwxr-xr-x. 2 root root 6 7月 19 10:12 aa lrwxrwxrwx. 1 root root 10 7月 19 10:19 softlink1 -> /tmp/1.txt [root@axiang01 ~]# //干掉软,靠avL [root@axiang01 ~]# rsync -avL /root/aaa/ /tmp/aaa_dest/ //增长L选项能够同步软连接的源文件,不过仍是以软链接命名(为了要和同步源目录下的文件命名保持一致) sending incremental file list softlink1 sent 1166 bytes received 32 bytes 2396.00 bytes/sec total size is 1053 speedup is 0.88 [root@axiang01 ~]# ls -l /tmp/aaa_dest/ 总用量 8 -rw-r--r--. 1 root root 12 7月 19 10:13 11.txt drwxr-xr-x. 2 root root 6 7月 19 10:12 aa -rw-r--r--. 1 root root 1041 7月 18 22:32 softlink1 此处与/tmp/1.txt同步 //同步啥是啥,别整没用的 --delete [root@axiang01 ~]# touch /tmp/aaa_dest/new.txt 人无我有~ [root@axiang01 ~]# rsync -avL /root/aaa/ /tmp/aaa_dest/ --delete 还有么? sending incremental file list ./ deleting new.txt //不一样步没用的 --exclude [root@axiang01 ~]# rm -rf /tmp/aaa_dest/* 重来 [root@axiang01 ~]# rsync -avL /root/aaa/ /tmp/aaa_dest/ --exclude "*.txt" --exclude "a*" 不一样步啥啥啥 sending incremental file list ./ softlink1 sent 1135 bytes received 34 bytes 2338.00 bytes/sec total size is 1041 speedup is 0.89 [root@axiang01 ~]# ls /tmp/aaa_dest/ softlink1 //exclude挺好使 //看同步大文件要多久 -P选项 [root@axiang01 ~]# !rm rm -rf /tmp/aaa_dest/* [root@axiang01 ~]# rsync -avP /root/aaa/ /tmp/aaa_dest/ 精确显示传输速度和% sending incremental file list ./ 11.txt 12 100% 0.00kB/s 0:00:00 (xfer#1, to-check=2/4) softlink1 -> /tmp/1.txt aa/ //哎呦喂,你新你有理 -auv 不一样步mtime落后的源文件 [root@axiang01 ~]# vi /tmp/aaa_dest/11.txt [root@axiang01 ~]# rsync -auv /root/aaa/ /tmp/aaa_dest/ sending incremental file list ./ sent 100 bytes received 16 bytes 232.00 bytes/sec total size is 22 speedup is 0.19 [root@axiang01 ~]# cat /tmp/aaa_dest/11.txt 6ofjeow afegs efewf:66 555 444 没变 //压缩传输 -z选项 [root@axiang01 ~]# rsync -az /root/aaa/ /tmp/aaa_dest/ //文件不大看不出效果
示例:登录
//推文件 没弄过密钥须要输入登陆密码 [root@axiang01 ~]# rsync -av /etc/passwd 192.168.83.22:/tmp/axiang.txt sending incremental file list passwd sent 1115 bytes received 31 bytes 99.65 bytes/sec total size is 1041 speedup is 0.91 //拉文件 [root@axiang01 ~]# rsync -avP 192.168.83.22:/tmp/axiang.txt /tmp/aaa.txt receiving incremental file list axiang.txt 1041 100% 1016.60kB/s 0:00:00 (xfer#1, to-check=0/1) sent 30 bytes received 1124 bytes 769.33 bytes/sec total size is 1041 speedup is 0.90