免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2447 | 回复: 1
打印 上一主题 下一主题

[FTP] Linux下同步远程FTP数据的几种思路 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-03-03 21:13 |只看该作者 |倒序浏览
原文地址:http://www.mike.org.cn/blog/?p=1246

  
  由于Rsync不支持通过FTP协议同步数据,Google后总结了以下几种解决这个问题的方法,暂时还未动手验证过。简单看了下,理论上是可行的。如果你按此文的方法去尝试了,记得留言分享下你的经验。

  一、先说比较简单的方法,就是用同步工具实现。

  A、 Unison

  Unison是windows和unix平台下都可以使用的文件同步工具,它能使两个文件夹(本地或网络上的)保持内容的一致。Unison有文字界面和图形界面,这里只介绍如何在文字界面下使用. unison拥有其它一些同步工具或文件系统的相同特性,但也有自己的特点:

  跨平台使用;

  对内核和用户权限没有特别要求;

  unison是双向的,它能自动处理两份拷贝中更新没有冲突的部分,有冲突的部分将会显示出来让用户选择更新策略;

  只要是能连通的两台主机,就可以运行unison,可以直接使用socket连接或安全的ssh连接方式,对带宽的要求不高,使用类似rsync的压缩传输协议。

  更详细介绍可见这里:linux 文件同步工具Unison的使用

  B、FTPSync

  FTPSync.pl is synchronizes a local directory tree and a remote FTP directory tree. It was initially written to automize web publishing, but other purposes might be fulfilled also. To DOWNLOAD FTPSync.pl, click on Summary/Web Site above.

  更详细介绍可见这里:FTPSync HomePage

            http://sourceforge.net/projects/ftpsync/

  C、csync (基于SMB或SFTP协议)

  csync with enhanced SFTP support is ready for download! csync is a bidirectional file synchronizer for Linux and allows to keep two copies of files and directories in sync. It uses widely adopted protocols like smb or sftp so that there is no need for a server component of csync. It is a user-level program which means there is no need to be a superuser. With pam_csync it is possible to provide roaming home directories in Linux and Active Directory environments.

  更详细介绍可见这里:csync HomePage

  二、Rsync+SSH

  下面这只是个例子:

rsync --delete --times --recursive --perms --owner --group --verbose --progress --stats -e ssh root@192.168.0.100:/folder1/ /folder2/
  
  更详细介绍可见这里:Using Rsync and SSH

  三、通过lftp的mirror模式(ncftp也有mirror模式)

  从FTP服务器上备份到本地

  A、命令行方式  

lftp -c "set ftp:list-options -a;
open ftp://user:password@your.ftp.com;
lcd ./web;
cd /web/public_html;
mirror --delete --use-cache --verbose --allow-chown
--allow-suid --no-umask --parallel=2 --exclude-glob .svn"
  
  B、脚本方式  

#!/bin/bash
HOST="your.ftp.host.dom"
USER="username"
PASS="password"
LCD="/path/of/your/local/dir"
RCD="/path/of/your/remote/dir"
lftp -c "set ftp:list-options -a;
open ftp://$USERPASS@$HOST;
lcd $LCD;
cd $RCD;
mirror --delete \
       --verbose \
       --exclude-glob a-dir-to-exclude/ \
       --exclude-glob a-file-to-exclude \
       --exclude-glob a-file-group-to-exclude* \
       --exclude-glob other-files-to-esclude"
  
  从本地恢复到FTP服务器上

  A、命令行方式  

lftp -c "set ftp:list-options -a;
open ftp://user:password@your.ftp.com;
lcd ./web;
cd /web/public_html;
mirror --reverse --delete --use-cache --verbose --allow-chown
--allow-suid --no-umask --parallel=2 --exclude-glob .svn"
  
  B、脚本方式  

#!/bin/bash
HOST="your.ftp.host.dom"
USER="username"
PASS="password"
LCD="/path/of/your/local/dir"
RCD="/path/of/your/remote/dir"
lftp -c "set ftp:list-options -a;
open ftp://$USERPASS@$HOST;
lcd $LCD;
cd $RCD;
mirror --reverse \
       --delete \
       --verbose \
       --exclude-glob a-dir-to-exclude/ \
       --exclude-glob a-file-to-exclude \
       --exclude-glob a-file-group-to-exclude* \
       --exclude-glob other-files-to-esclude"
  
  两种方式间主要的差别就是在--reverse选项上,有这个选项就是put files,反之则是get files。

  更详细介绍可见这里:lftp的使用

            用lftp备份文件

            lftp命令详解

论坛徽章:
0
2 [报告]
发表于 2010-03-04 22:44 |只看该作者
{:3_190:}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP