在对rsync服务器配置结束以后,下一步就需要在客户端发出rsync命令来实现将服务器的文件备份到客户端来。rsync是一个功能强大的工具,其命令也有很多功能特色选项。
Rsync的命令格式可以为以下六种:
rsync [OPTION]... SRC DEST
rsync [OPTION]... SRC [USER@]HOST:DEST
rsync [OPTION]... [USER@]HOST:SRC DEST
rsync [OPTION]... [USER@]HOST::SRC DEST
rsync [OPTION]... SRC [USER@]HOST::DEST
rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
对于以上六种命令格式,rsync有六种不同的工作模式:
(1)拷贝本地文件。当src和des路径信息都不包含有单个“:”分隔符的时候就启动这种工作模式。
[root@centos65 local]# rsync -a test test-copy/
[root@centos65 local]#
[root@centos65 local]# ll
total 4
drwxr-xr-x 2 root root 6 Sep 23 2011 bin
drwxr-xr-x 2 root root 6 Sep 9 21:10 data
drwxr-xr-x 2 root root 6 Sep 23 2011 etc
drwxr-xr-x 2 root root 6 Sep 23 2011 games
drwxr-xr-x 6 root root 4096 Sep 11 10:57 importsource
drwxr-xr-x 2 root root 32 Jan 14 2015 include
drwxr-xr-x 2 root root 6 Sep 23 2011 lib
drwxr-xr-x 2 root root 6 Sep 23 2011 lib64
drwxr-xr-x 2 root root 6 Sep 23 2011 libexec
drwxr-xr-x 2 root root 6 Sep 23 2011 sbin
drwxr-xr-x 5 root root 46 Dec 4 2013 share
drwxr-xr-x 3 root root 22 Aug 17 12:42 sourcedata
drwxr-xr-x 2 root root 6 Sep 23 2011 src
drwxr-xr-x 2 root root 108 Sep 24 16:32 test
drwxr-xr-x 3 root root 17 Sep 25 09:09 test-copy
drwxr-xr-x 3 root root 57 Aug 19 09:58 testorder
[root@centos65 local]#
[root@centos65 local]# cd test-copy/
[root@centos65 test-copy]# ll
total 0
drwxr-xr-x 2 root root 108 Sep 24 16:32 test
[root@centos65 test-copy]#
[root@centos65 test-copy]#
[root@centos65 test-copy]#
[root@centos65 test-copy]# cd test
[root@centos65 test]# ll
total 28
-rw-r--r-- 1 root root 12 Sep 24 16:32 test.pdf
-rw-r--r-- 1 root root 10240 Sep 24 15:45 test.tar
-rw-r--r-- 1 root root 521 Sep 24 15:53 test.tar.gz
-rw-r--r-- 1 root root 1790 Sep 24 15:44 tracks001.conf
-rw-r--r-- 1 root root 942 Sep 24 15:44 新建文本文档 (2).txt
[root@centos65 test]# cd ..
[root@centos65 test-copy]#
[root@centos65 test-copy]# ll
total 0
drwxr-xr-x 2 root root 108 Sep 24 16:32 test
[root@centos65 test-copy]#
[root@centos65 test-copy]#
[root@centos65 test-copy]# cd ..
[root@centos65 local]#
[root@centos65 local]# ll
total 4
drwxr-xr-x 2 root root 6 Sep 23 2011 bin
drwxr-xr-x 2 root root 6 Sep 9 21:10 data
drwxr-xr-x 2 root root 6 Sep 23 2011 etc
drwxr-xr-x 2 root root 6 Sep 23 2011 games
drwxr-xr-x 6 root root 4096 Sep 11 10:57 importsource
drwxr-xr-x 2 root root 32 Jan 14 2015 include
drwxr-xr-x 2 root root 6 Sep 23 2011 lib
drwxr-xr-x 2 root root 6 Sep 23 2011 lib64
drwxr-xr-x 2 root root 6 Sep 23 2011 libexec
drwxr-xr-x 2 root root 6 Sep 23 2011 sbin
drwxr-xr-x 5 root root 46 Dec 4 2013 share
drwxr-xr-x 3 root root 22 Aug 17 12:42 sourcedata
drwxr-xr-x 2 root root 6 Sep 23 2011 src
drwxr-xr-x 2 root root 108 Sep 24 16:32 test
drwxr-xr-x 3 root root 17 Sep 25 09:09 test-copy
drwxr-xr-x 3 root root 57 Aug 19 09:58 testorder
(2)
使用一个远程shell程序来实现将远程机器的内容拷贝到本地机器。
[root@centos65 test]# rsync test.pdf root@10.0.96.180:/usr/local/test-liumengyang
Warning: Permanently added '10.0.96.180' (RSA) to the list of known hosts.
root@10.0.96.180's password:
drwxr-xr-x. 2 root root 4096 Sep 25 09:20 test-liumengyang
You have new mail in /var/spool/mail/root
[root@localhost local]#
[root@localhost local]#
[root@localhost local]#
[root@localhost local]# cd test-liumengyang/
[root@localhost test-liumengyang]# ll
total 4
-rw-r--r--. 1 root root 12 Sep 25 09:20 test.pdf
[root@localhost test-liumengyang]#
[root@localhost test-liumengyang]#
[root@localhost test-liumengyang]#
[root@localhost test-liumengyang]# ll -a
total 12
drwxr-xr-x. 2 root root 4096 Sep 25 09:20 .
drwxr-xr-x. 17 root root 4096 Sep 25 09:18 ..
-rw-r--r--. 1 root root 12 Sep 25 09:20 test.pdf
(3)
使用一个远程shell程序来实现将远程机器的内容拷贝到本地机器。当src路径包含当个冒号的时候,启用该模式。
[root@centos65 local]# rsync root@10.0.96.180:/usr/local/test-liumengyang/test.pdf /usr/local/
root@10.0.96.180's password:
[root@centos65 local]#
[root@centos65 local]#
[root@centos65 local]# ll
total 8
drwxr-xr-x 2 root root 6 Sep 23 2011 bin
drwxr-xr-x 2 root root 6 Sep 9 21:10 data
drwxr-xr-x 2 root root 6 Sep 23 2011 etc
drwxr-xr-x 2 root root 6 Sep 23 2011 games
drwxr-xr-x 6 root root 4096 Sep 11 10:57 importsource
drwxr-xr-x 2 root root 32 Jan 14 2015 include
drwxr-xr-x 2 root root 6 Sep 23 2011 lib
drwxr-xr-x 2 root root 6 Sep 23 2011 lib64
drwxr-xr-x 2 root root 6 Sep 23 2011 libexec
drwxr-xr-x 2 root root 6 Sep 23 2011 sbin
drwxr-xr-x 5 root root 46 Dec 4 2013 share
drwxr-xr-x 3 root root 22 Aug 17 12:42 sourcedata
drwxr-xr-x 2 root root 6 Sep 23 2011 src
drwxr-xr-x 2 root root 108 Sep 24 16:32 test
drwxr-xr-x 3 root root 17 Sep 25 09:09 test-copy
drwxr-xr-x 3 root root 57 Aug 19 09:58 testorder
-rw-r--r-- 1 root root 12 Sep 25 09:42 test.pdf
4)从远程rsync服务器中拷贝文件到本地机。当SRC路径信息包含"::"分隔符时启动该模式。如:rsync -av root@172.16.78.192::www /databack
5)从本地机器拷贝文件到远程rsync服务器中。当DST路径信息包含"::"分隔符时启动该模式。如:rsync -av /databack root@172.16.78.192::www
6)列远程机的文件列表。这类似于rsync传输,不过只要在命令中省略掉本地机信息即可。如:rsync -v rsync://172.16.78.192/www