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 [email protected]:/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.
[email protected]'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对目标文件进行同步删除

[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
[email protected]'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
[email protected]'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
[email protected]'s password: 
sending incremental file list

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

你可能感兴趣的:(rsync工具介绍、rsync常用选项、rsync通过ssh同步)