shallow丿ovecentos
文件同步工具rsyncbash
[root@localhost ~]# yum install -y rsync Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * epel: mirrors.tongji.edu.cn Resolving Dependencies --> Running transaction check ---> Package rsync.x86_64 0:3.0.9-18.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================== Package Arch Version Repository Size =================================================================================================== Installing: rsync x86_64 3.0.9-18.el7 base 360 k Transaction Summary =================================================================================================== Install 1 Package Total download size: 360 k Installed size: 732 k Downloading packages: rsync-3.0.9-18.el7.x86_64.rpm | 360 kB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : rsync-3.0.9-18.el7.x86_64 1/1 Verifying : rsync-3.0.9-18.el7.x86_64 1/1 Installed: rsync.x86_64 0:3.0.9-18.el7 Complete!
[root@localhost ~]# rsync -av /etc/passwd /tmp/1.txt sending incremental file list passwd sent 1506 bytes received 31 bytes 3074.00 bytes/sec total size is 1432 speedup is 0.93
-avssh
[root@localhost ~]# ls 111 anaconda-ks.cfg [root@localhost ~]# rsync -av /root/111/ /tmp/111_dest/ sending incremental file list created directory /tmp/111_dest ./ 1.txt 2.txt 3.txt sent 192 bytes received 72 bytes 528.00 bytes/sec total size is 0 speedup is 0.00 [root@localhost ~]# ls 111 anaconda-ks.cfg [root@localhost ~]# ls /tmp/ 111_dest ipt.txt
--delete工具
[root@localhost ~]# touch /tmp/111_dest/new.txt [root@localhost ~]# rsync -av /root/111/ /tmp/111_dest/ sending incremental file list ./ sent 75 bytes received 15 bytes 180.00 bytes/sec total size is 0 speedup is 0.00 [root@localhost ~]# ls /tmp/111_dest/ 1.txt 2.txt 3.txt new.txt
[root@localhost ~]# touch /tmp/111_dest/new.txt [root@localhost ~]# rsync -av --delete /root/111/ /tmp/111_dest/ sending incremental file list ./ deleting new.txt sent 75 bytes received 15 bytes 180.00 bytes/sec total size is 0 speedup is 0.00 [root@localhost ~]# ls /tmp/111_dest/ 1.txt 2.txt 3.txt
--excludecode
[root@localhost ~]# rm -rf /tmp/111_dest/* [root@localhost ~]# rsync -av --exclude "1*" /root/111/ /tmp/111_dest/ sending incremental file list ./ 2.txt 3.txt sent 139 bytes received 53 bytes 384.00 bytes/sec total size is 0 speedup is 0.00 [root@localhost ~]# ls /tmp/111_dest/ 2.txt 3.txt
-avPip
[root@localhost ~]# rm -rf /tmp/111_dest/* [root@localhost ~]# rsync -avP /root/111/ /tmp/111_dest/ sending incremental file list ./ 1.txt 18 100% 0.00kB/s 0:00:00 (xfer#1, to-check=2/4) 2.txt 12 100% 11.72kB/s 0:00:00 (xfer#2, to-check=1/4) 3.txt 6 100% 5.86kB/s 0:00:00 (xfer#3, to-check=0/4) sent 240 bytes received 72 bytes 624.00 bytes/sec total size is 36 speedup is 0.12
-avPuci
[root@localhost ~]# echo "hello" > 111/1.txt [root@localhost ~]# rsync -avP /root/111/ /tmp/111_dest/ sending incremental file list 1.txt 6 100% 0.00kB/s 0:00:00 (xfer#1, to-check=2/4) sent 121 bytes received 31 bytes 304.00 bytes/sec total size is 24 speedup is 0.16 [root@localhost ~]# cat /tmp/111_dest/1.txt hello
[root@localhost ~]# echo "hello" >> !$ echo "hello" >> /tmp/111_dest/1.txt [root@localhost ~]# rsync -avPu /root/111/ /tmp/111_dest/ sending incremental file list sent 72 bytes received 12 bytes 168.00 bytes/sec total size is 24 speedup is 0.29 [root@localhost ~]# cat /tmp/111_dest/1.txt hello hello [root@localhost ~]# cat 111/1.txt hello
Linux主機A:192.168.9.134rem
[root@localhost ~]# rsync -avP /root/111/ root@192.168.9.233:/root/111_new/ The authenticity of host '192.168.9.223 (192.168.9.223)' can't be established. ECDSA key fingerprint is 36:5f:cc:8b:04:f9:7b:2e:0f:8c:39:38:37:c3:d2:3a. Are you sure you want to continue connecting (yes/no)? y Please type 'yes' or 'no': yes Warning: Permanently added '192.168.9.223' (ECDSA) to the list of known hosts. root@192.168.9.223's password: bash: rsync: command not found rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: remote command not found (code 127) at io.c(605) [sender=3.0.9]
主機B必須也要安裝rsync包同步
[root@localhost ~]# rsync -avP /root/111/ root@192.168.9.233:/root/111_new/ root@192.168.9.233's password: sending incremental file list created directory /root/111_new ./ 1.txt 6 100% 0.00kB/s 0:00:00 (xfer#1, to-check=2/4) 2.txt 12 100% 11.72kB/s 0:00:00 (xfer#2, to-check=1/4) 3.txt 6 100% 5.86kB/s 0:00:00 (xfer#3, to-check=0/4) sent 228 bytes received 72 bytes 120.00 bytes/sec total size is 24 speedup is 0.08
Linux主機B:192.168.9.223it
[root@centos11233 ~]# ls 111_new anaconda-ks.cfg
推文件與拉文件
Linux主機A:192.168.9.134
[root@localhost ~]# rsync -avP root@192.168.9.233:/root/111_new/ /root/111_dest/ root@192.168.9.233's password: receiving incremental file list created directory /root/111_dest ./ 1.txt 6 100% 5.86kB/s 0:00:00 (xfer#1, to-check=2/4) 2.txt 12 100% 11.72kB/s 0:00:00 (xfer#2, to-check=1/4) 3.txt 6 100% 5.86kB/s 0:00:00 (xfer#3, to-check=0/4) sent 71 bytes received 233 bytes 67.56 bytes/sec total size is 24 speedup is 0.08 [root@localhost ~]# ls 111 111_dest anaconda-ks.cfg
指定端口-e "ssh -p 端口號"
[root@localhost ~]# rsync -avP -e "ssh -p 22" /etc/passwd root@192.168.9.233:/root/1.txt root@192.168.9.233's password: sending incremental file list passwd 1432 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/1) sent 1506 bytes received 31 bytes 614.80 bytes/sec total size is 1432 speedup is 0.93
[root@localhost ~]# ssh -p 22 192.168.9.233 root@192.168.9.233's password: Last failed login: Wed Dec 6 03:34:39 CST 2017 from 192.168.9.134 on ssh:notty There was 1 failed login attempt since the last successful login. Last login: Wed Dec 6 00:33:06 2017 from 192.168.9.1 [root@centos11233 ~]# [root@centos11233 ~]# exit logout Connection to 192.168.9.233 closed.