7.18 10.28-10.31

10.28 rsync工具介绍

rsync是一个实用的同步工具

 

需求:A目录的数据实时更新,将A的数据拷贝到B目录,每隔一小时拷贝一次

使用cp命令:

1 A目录中找出最近1小时新增的内容拷贝到B(比较麻烦)

2 直接拷贝A目录的所有内容将B目录覆盖(浪费时间和磁盘IO

cp命令不适用

 

rsync可以实现增量更新(rsync只会同步新增和有内容变更的文件);

支持远程同步(将数据同步到不同ip的另一台机器上);

 

安装rsync

[root@hyc-01-01 ~]# yum install -y rsync

 

passwd同步到tmp目录下并改名为1.txt

[root@hyc-01-01 ~]# rsync -av /etc/passwd /tmp/1.txt

sending incremental file list

passwd

sent 938 bytes  received 35 bytes  1,946.00 bytes/sec

total size is 846  speedup is 0.87

-a 包含多个选项

-v 可视化,可以看到拷贝的过程

 

将文件同步到远程机器的特定目录

[root@hyc-01-01 ~]# rsync -av /etc/passwd root@192.168.31.128:/tmp/1234.txt

The authenticity of host '192.168.31.128 (192.168.31.128)' can't be established.

ECDSA key fingerprint is SHA256:0SErfGbbc3AfFcxC92Tav9X/T/bOn8wfnvum/wnw5Xs.

ECDSA key fingerprint is MD5:b7:d4:e4:4a:4a:33:29:99:1a:2e:45:94:d9:40:17:fb.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.31.128' (ECDSA) to the list of known hosts.

[email protected]'s password:

sending incremental file list

passwd

sent 938 bytes  received 35 bytes  67.10 bytes/sec

total size is 846  speedup is 0.87

其中root@可以省略,此时使用执行当前命令的用户作为登录用户

 

将远程机器的某文件拷贝到当前机器某个目录下

[root@hyc-01-01 ~]# rsync -av [email protected]:/etc/passwd /tmp/passwddd

[email protected]'s password:

receiving incremental file list

passwd

sent 43 bytes  received 938 bytes  130.80 bytes/sec

total size is 846  speedup is 0.86

[root@hyc-01-01 ~]# ls /tmp/passwddd

/tmp/passwddd

 


猜你喜欢

转载自blog.51cto.com/12216458/2146978