步骤一:基本同步操作
1)准备测试目录及文件
创建两个测试目录/opt/dir1、/opt/dir2,并在/opt/dir1目录下建立测试文件1.txt、测试子目录2.dir:
[root@pc205 ~]# mkdir /opt/dir1 /opt/dir2
[root@pc205 ~]# ifconfig eth0 > /opt/dir1/1.txt
[root@pc205 ~]# mkdir /opt/dir1/2.dir
[root@pc205 ~]# ls -l /opt/dir1/ /opt/dir2/ //确认结果
/opt/dir1/:
总用量 8
-rw-r--r--. 1 root root 497 4月 26 16:48 1.txt
drwxr-xr-x. 2 root root 4096 4月 26 16:51 2.dir
/opt/dir2/:
总用量 0
2)验证-a归档选项、源目录后是否跟/的作用
未添加-a选项时,当被同步的文档包含目录时,无法向下递归:
[root@pc205 ~]# rsync /opt/dir1 /opt/dir2
skipping directory dir1 //目录被跳过
[root@pc205 ~]# ls -l /opt/dir1/ /opt/dir2/
/opt/dir1/:
总用量 8
-rw-r--r--. 1 root root 497 4月 26 16:48 1.txt
drwxr-xr-x. 2 root root 4096 4月 26 16:51 2.dir
/opt/dir2/: //未同步任何文档
总用量 0
添加-a选项,再次执行上述同步,被同步的是整个/opt/dir1目录(末尾无/):
[root@pc205 ~]# rsync -a /opt/dir1 /opt/dir2
[root@pc205 ~]# ls -l /opt/dir1/ /opt/dir2/
/opt/dir1/

最低0.47元/天 解锁文章
606

被折叠的 条评论
为什么被折叠?



