rsync工具用于将文件和目录从一个位置同步到另一个位置。同步的位置可以在本地服务器或远程服务器上。 |
[root@localhost ~]# yum -y install rsync
实例一:本机中的两个目录进行同步
要同步本地计算机中的两个目录,使用rsync -zvr
命令:
[root@localhost ~]# rsync -zvr /var/log/ /root/temp/ sending incremental file list btmp dnf.librepo.log ... sssd/sssd_implicit_files.log sssd/sssd_nss.log tuned/tuned.log sent 516,136 bytes received 605 bytes 1,033,482.00 bytes/sec total size is 5,451,242 speedup is 10.55
参数解释:
- -z 启用压缩
- -v 输出详细信息
- -r 表示递归
查看一下/root/temp目录,发现rsync在同步期间未保留时间戳。
实例二:使用rsync -a在同步期间保留时间戳
rsync命令的-a
选项表示存档模式。-a
选项递归同步、保留符号链接、保留权限、保留时间戳、保留所有者和组。
现在,执行以下命令,然后查看文件的时间:
[root@localhost ~]# rsync -azv /var/log/ /root/temp/ sending incremental file list ./ btmp dnf.librepo.log dnf.log dnf.rpm.log ... sssd/sssd_nss.log tuned/ tuned/tuned.log sent 516,231 bytes received 629 bytes 1,033,720.00 bytes/sec total size is 5,451,789 speedup is 10.55
如下所示,rsync在同步期间保留了时间戳。