标签:二次 error remote path oca /etc/ images city 举例
八周二次课(1月30日)10.28 rsync工具介绍
10.29/10.30 rsync常用选项
10.31 rsync通过ssh同步
Linux系统下有很多数据备份工具,常用的是rsync,从字面意思理解为remote sync(远程同步)。rsync不仅可以远程同步数据(类似于scp),而且可以本地同步数据(类似于cp),但不同于cp或者scp的一点是,它不会覆盖以前的数据(如果数据已经存在),而是先判断已经存在的数据和新数据的差异,只有数据不同时才会把不相同的部分覆盖。
[root@localhost ~]# rsync -av /etc/passwd /tmp/1.txt
sending incremental file list
passwd
sent 2465 bytes received 31 bytes 4992.00 bytes/sec
total size is 2391 speedup is 0.96
上例中把/etc/passwd同步到/tmp/目录下,并改名为1.txt,如果要改成远程复制,数据备份的格式是: 用户名@IP:path,比如192.168.188.128:/root/.具体用法如下:
[root@localhost ~]# rsync -av /etc/passwd root@192.168.72.133:/tmp/1.txt
The authenticity of host ‘192.168.72.133 (192.168.72.133)‘ can‘t be established.
ECDSA key fingerprint is 54:1a:44:33:2e:df:c2:58:41:cf:f3:d2:e3:69:87:b7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.72.133‘ (ECDSA) to the list of known hosts.
root@192.168.72.133‘s password:
sending incremental file list
passwd
sent 2465 bytes received 253 bytes 175.35 bytes/sec
total size is 2391 speedup is 0.88
这里要求远程的机器也必须安装有rsync,需要验证密码是因为这里没有做两机互联.
rsync是一个功能非常强大的工具,其命令也有很多功能特色选项。
上述选项笔记多,常用的有-a,-v,-z,--delete和--exclude.
3.测试rsync的选项
为了更换的测试,需要新建目录和文件
[root@localhost ~]# ls
anaconda-ks.cfg grep httpd-2.4.29.tar.gz [root@localhost split_dir
awk httpd-2.4.29 initial-setup-ks.cfg sed xaa
## ls 下没有合适的目录和文件,只能重新建
[root@localhost ~]# mkdir rsync
[root@localhost ~]# cd rsync
[root@localhost rsync]# mkdir 111
[root@localhost rsync]# touch 1 2 3 /root/123.txt
[root@localhost rsync]# ln -s /root/123.txt ./134.txt //建立软链接
[root@localhost rsync]# ls -l
总用量 0
-rw-r--r-- 1 root root 0 1月 31 23:22 1
3.1 -a选项用法
3.2 使用-L的用法
[root@localhost ~]# rsync -avL ./rsync/ ./test2/
sending incremental file list
111/
111/123.txt
sent 158 bytes received 35 bytes 386.00 bytes/sec
total size is 0 speedup is 0.00
[root@localhost ~]# ls -l test2/
总用量 0
-rw-r--r-- 1 root root 0 1月 31 23:22 1
drwxr-xr-x 2 root root 21 1月 31 23:50 111
-rw-r--r-- 1 root root 0 1月 31 23:22 134.txt
-rw-r--r-- 1 root root 0 1月 31 23:22 2
-rw-r--r-- 1 root root 0 1月 31 23:22 3
-rw-r--r-- 1 root root 0 1月 31 23:22 321.txt
3.3 使用delete选项
[root@localhost ~]# rsync -avL --delete ./rsync/ ./test2/
sending incremental file list
sent 116 bytes received 13 bytes 258.00 bytes/sec
total size is 0 speedup is 0.00
[root@localhost ~]# ls
123.txt 556.txt awk httpd-2.4.29 initial-setup-ks.cfg rsync split_dir xaa
321.txt anaconda-ks.cfg grep httpd-2.4.29.tar.gz [root@localhost sed test2
3.4 使用--exclude选项
[root@localhost ~]# mkdir test1
[root@localhost ~]# touch test1/4
[root@localhost ~]# rsync -a --exclude="4" test1/ test2/
[root@localhost ~]# ls test1
4
第一种方法:把文件推出去
[root@localhost ~]# rsync -avL test2/ 192.168.72.133:/root/xavi/
root@192.168.72.133‘s password:
sending incremental file list
./
1
134.txt
2
3
321.txt
111/
111/123.txt
sent 356 bytes received 133 bytes 75.23 bytes/sec
total size is 0 speedup is 0.00
第二章方法:把文件拉过来,测试失败!!!!未找到原因
[root@localhost ~]# rsync -avP 192.168.72.132:/root/xavi/ ./test1/
ssh: connect to host 192.168.72.132 port 22: No route to host
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(605) [Receiver=3.0.9]
[root@localhost ~]# rsync -avP 192.168.72.132:/root/xavi/ ./test1/
ssh: connect to host 192.168.72.132 port 22: No route to host
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(605) [Receiver=3.0.9]
标签:二次 error remote path oca /etc/ images city 举例
原文地址:http://blog.51cto.com/12995218/2067670