Chinaunix首页 | 论坛 | 博客

  • 博客访问: 896703
  • 博文数量: 226
  • 博客积分: 10077
  • 博客等级: 上将
  • 技术积分: 2708
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-25 14:36
文章分类

全部博文(226)

文章存档

2010年(15)

2009年(82)

2008年(129)

我的朋友

分类: LINUX

2010-11-19 16:31:26

关于rsync的断点续传

经常copy大文件,由于服务器、路由等网络的不确定性,老是出现

remote server not responding.
于是查了下资料,发现rsync这个工具支持断点续传功能,这里介绍一下。
rsync也分服务器端和客户端,使用man查看帮助信息,我们发现rsync有六种不同的工作模式:
       Local:  rsync [OPTION...] SRC... [DEST]

       Access via remote shell:
         Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
         Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

       Access via rsync daemon:
         Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
               rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
         Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
               rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

       List remote files: rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
  1. 拷贝本地文件;当SRC和DES路径信息都不包含有单个冒号":"分隔符时就启动这
种工作模式。
  2.使用一个远程shell程序(如rsh、ssh)来实现将本地机器的内容拷贝到远程机器

。当DST
路径地址包含单个冒号":"分隔符时启动该模式。
  3.使用一个远程shell程序(如rsh、ssh)来实现将远程机器的内容拷贝到本地机器

。当SRC
地址路径包含单个冒号":"分隔符时启动该模式。
  4. 从远程rsync服务器中拷贝文件到本地机。当SRC路径信息包含"::"分隔符时启动

该模式。
  5. 从本地机器拷贝文件到远程rsync服务器中。当DST路径信息包含"::"分隔符时启

动该模式。
  6. 列远程机的文件列表。这类似于rsync传输,不过只要在命令中省略掉本地机信

息即可。
下面以实例来说明:
  # rsync -vazu -progress cnangel@10.1.6.160:~/works/ ~/works
  v:详细提示
  a:以archive模式操作,复制目录、符号连接,等价于 -rlptgoD 。
  z:压缩
  u:只进行更新,防止本地新文件被重写,注意两者机器的时钟的同时
  -progress:指显示
  以上命令是保持客户机10.1.6.160上的$HOME/works目录和当前机器的$HOME/works目录同
步。
这经常是我们所说的镜像同步就是这么来的,如果断点续传呢?rsync完全可以做到这一点。man手册再次告诉我们:
--partial
      By default, rsync will delete any partially  transferred  file  if  the  transfer  is
      interrupted. In some circumstances it is more desirable to keep partially transferred
      files. Using the --partial option tells rsync to keep the partial file  which  should
      make a subsequent transfer of the rest of the file much faster.

--partial-dir=DIR
      A better way to keep partial files than the --partial option is to specify a DIR that
      will be used to hold the partial data (instead of writing it out to  the  destination
      file).   On  the  next  transfer,  rsync will use a file found in this dir as data to
      speed up the resumption of the transfer and then delete it after it  has  served  its
      purpose.
默认的情况下,当rsync传输中断后,新的rsync传输将删除所有的未完成的残余文件片段,然后开始新的传输。而使用--partial后,将会进行我们所说的断点续传。
值得注意的是-P这个参数是综合了--partial --progress两个参数,所以rsync的断点续传可以用下面的例子来说明:
# rsync -avzP /tmp/bigfile cnangel@10.1.6.160:/tmp/bigfile
另外,还有两个参数也经常用到:
  t:修改次数
  r:递归方式
阅读(3599) | 评论(1) | 转发(0) |
0

上一篇:ip138归属地查询perl脚本

下一篇:没有了

给主人留下些什么吧!~~

chinaunix网友2010-11-20 16:48:17

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com