rsync工具介紹、rsync常用選項、rsync通過ssh同步

rsync工具介紹

Linux文件同步工具-rsync

安裝rsync
使用rsync同步到本機
同步到其它機器

[root@wsl-001 ~]# rsync -av /etc/passwd /tmp/1.txt
sending incremental file list
passwd

sent 1129 bytes  received 31 bytes  2320.00 bytes/sec
total size is 1055  speedup is 0.91
[root@wsl-001 ~]# rsync -av /etc/passwd root@172.16.79.141:/tmp/1.txt
The authenticity of host '172.16.79.141 (172.16.79.141)' can't be established.
ECDSA key fingerprint is SHA256:d/C47ZKXtLAJujg0pBt/al73bQ+FaJY78vspcP4TaI4.
ECDSA key fingerprint is MD5:ac:81:93:09:26:bf:48:e8:0c:31:3d:48:1b:7b:3f:43.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.79.141' (ECDSA) to the list of known hosts.
root@172.16.79.141's password: 
sending incremental file list

sent 31 bytes  received 12 bytes  7.82 bytes/sec
total size is 1055  speedup is 24.53

rsync常用選項

rsync常用選項

同步目錄并修改名字

[root@wsl-001 grep]# ln -s /root/a.txt /root/grep/a.txt
[root@wsl-001 grep]# ls -l
總用量 12
lrwxrwxrwx  1 root root  11 3月  25 21:51 a.txt -> /root/a.txt
-rw-r--r--. 1 root root 511 1月  24 16:53 inittab
-rw-r--r--. 1 root root 922 1月  24 22:38 passwd
-rw-r--r--. 1 root root 922 1月  24 22:25 passwd1
[root@wsl-001 grep]# rsync -av /root/grep/ /tmp/grep_test/
sending incremental file list
./
a.txt -> /root/a.txt

sent 108 bytes  received 18 bytes  252.00 bytes/sec
total size is 2366  speedup is 18.78
[root@wsl-001 grep]# ls -l /tmp/grep_test/
總用量 12
lrwxrwxrwx 1 root root  11 3月  25 21:51 a.txt -> /root/a.txt
-rw-r--r-- 1 root root 511 1月  24 16:53 inittab
-rw-r--r-- 1 root root 922 1月  24 22:38 passwd
-rw-r--r-- 1 root root 922 1月  24 22:25 passwd1

運用L選項,拷貝軟連接的源文件

[root@wsl-001 grep]# ls -l /tmp/grep_test/
總用量 12
lrwxrwxrwx 1 root root  11 3月  25 21:51 a.txt -> /root/a.txt
-rw-r--r-- 1 root root 511 1月  24 16:53 inittab
-rw-r--r-- 1 root root 922 1月  24 22:38 passwd
-rw-r--r-- 1 root root 922 1月  24 22:25 passwd1
[root@wsl-001 grep]# rsync -avL /root/grep/ /tmp/grep_test/
sending incremental file list
a.txt

sent 269 bytes  received 31 bytes  600.00 bytes/sec
total size is 2495  speedup is 8.32
[root@wsl-001 grep]# ls -l /tmp/grep_test/
總用量 16
-rw-r--r-- 1 root root 140 1月  24 11:44 a.txt
-rw-r--r-- 1 root root 511 1月  24 16:53 inittab
-rw-r--r-- 1 root root 922 1月  24 22:38 passwd
-rw-r--r-- 1 root root 922 1月  24 22:25 passwd1

運用--delete對目標(biāo)文件進行同步刪除

[root@wsl-001 grep]# ls /root/grep/
a.txt  inittab  passwd  passwd1
[root@wsl-001 grep]# ls /tmp/grep_test/
a.txt  inittab  passwd  passwd1
[root@wsl-001 grep]# touch /tmp/grep_test/111
[root@wsl-001 grep]# rsync -avL --delete  /root/grep/ /tmp/grep_test/
sending incremental file list
./
deleting 111

sent 89 bytes  received 15 bytes  208.00 bytes/sec
total size is 2495  speedup is 23.99
[root@wsl-001 grep]# ls /tmp/grep_test/
a.txt  inittab  passwd  passwd1

運用--exclude過濾掉txt文件

[root@wsl-001 grep]# ls /tmp/grep_test/
a.txt  inittab  passwd  passwd1
[root@wsl-001 grep]# rm -f /tmp/grep_test/a.txt 
[root@wsl-001 grep]# ls /tmp/grep_test/
inittab  passwd  passwd1
[root@wsl-001 grep]# ls /root/grep/
a.txt  inittab  passwd  passwd1
[root@wsl-001 grep]# rsync -avL --exclude "*.txt"  /root/grep/ /tmp/grep_test/
sending incremental file list
./

sent 75 bytes  received 15 bytes  180.00 bytes/sec
total size is 2355  speedup is 26.17
[root@wsl-001 grep]# ls /tmp/grep_test/
inittab  passwd  passwd1

運用P選項顯示傳輸速度

[root@wsl-001 grep]# rsync -avP  /root/grep/ /tmp/grep_test/
sending incremental file list
created directory /tmp/grep_test
./
a.txt -> /root/a.txt
inittab
         511 100%    0.00kB/s    0:00:00 (xfer#1, to-check=2/5)
passwd
         922 100%  900.39kB/s    0:00:00 (xfer#2, to-check=1/5)
passwd1
         922 100%  900.39kB/s    0:00:00 (xfer#3, to-check=0/5)

sent 2592 bytes  received 75 bytes  5334.00 bytes/sec
total size is 2366  speedup is 0.89

rsync通過ssh同步

rsync通過ssh同步
[root@wsl-001 grep]# rsync -av  /root/grep/passwd 172.16.79.141:/tmp/test1
root@172.16.79.141's password: 
sending incremental file list
passwd

sent 78 bytes  received 43 bytes  34.57 bytes/sec
total size is 922  speedup is 7.62
[root@wsl-001 grep]# rsync -av  /root/grep/passwd 172.16.79.141:/tmp/test1
root@172.16.79.141's password: 
sending incremental file list

sent 31 bytes  received 12 bytes  9.56 bytes/sec
total size is 922  speedup is 21.44

指定端口

[root@wsl-001 grep]# rsync -av -e "ssh -p  22"  /root/grep/passwd 172.16.79.141:/tmp/test1
root@172.16.79.141's password: 
sending incremental file list

sent 31 bytes  received 12 bytes  12.29 bytes/sec
total size is 922  speedup is 21.44
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容