当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > 用rsync实现网站镜像和备份

Unix/Linux
Creating a OpenBSD 3.5 bootable CD
解决Fatal error: Call to undefined function: preg_match()
[工具 使用 原创] ls可以是彩色的,df也可以是彩色的
ipfilter+squid配置实例
UNIX痛恨者手册
postfix+ldap+sasl2+courier-imap for freebsd完全ports
硬盘、分区引导和操作系统加载程序
Unix/Linux下的“魔法兔仔”, webmin
solaris10 apache2 的问题
解决启动DHCP客户端时,出现unknown 主机名称的方法
A1000的电池用完了会有什么严重后果
Solaris 2.6+Ultra5内置扬声器故障诊断实例
各种shell下文件名补全功能的使用
民工日记--- We sell dream
让你的终端同时支持中文和 PP 的背景(转载收藏)
民工日记 --不变的变化
配置Solaris上网
民工日记--不鼓励也不反对
Solaris Security Toolkit 4.2
民工日记--无奈

Unix/Linux 中的 用rsync实现网站镜像和备份


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-15   浏览: 69 ::
收藏到网摘: n/a

服务器端

 

# more /etc/rsyncd.conf

uid = nobody

gid = nobody

use chroot = no

max connections = 4

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

 

[wap]

path = /usr/local/backup

ignore errors

read only = yes

list = no

hosts allow = 192.168.1.2

hosts deny = 0.0.0.0/32

auth users = backup

secrets file = /etc/rsyncd.secrets

 

 

# more /etc/rsyncd.secrets

backup:backup

 

# chmod 600 /etc/rsyncd.secrets

# chown root.root /etc/rsyncd.secrets

 

# rsync --daemon

 

客户端

# more /etc/rsync.pass

backup

 

# more /etc/rsync.sh

rsync -avP  [email protected]::www /usr/local/backup

 --password-file=/etc/rsync.pass

 

   

FAQ

Q:如何通过ssh进行rsync,而且无须输入密码?

A:可以通过以下几个步骤

 

1. 通过ssh-keygenserver A上建立SSH keys,不要指定密码,你会在~/.ssh下看到identityidentity.pub文件

2. server B上的home目录建立子目录.ssh

3. Aidentity.pub拷贝到server B

4. identity.pub加到~[user b]/.ssh/authorized_keys

5. 于是server A上的A用户,可通过下面命令以用户B sshserver B上了

e.g. ssh -l userB serverB

这样就使server A上的用户A就可以ssh以用户B的身份无需密码登陆到server B上了。

 

Q:如何通过在不危害安全的情况下通过防火墙使用rsync?

A:解答如下:

 

这通常有两种情况,一种是服务器在防火墙内,一种是服务器在防火墙外。无论哪种情况,通常还是使用ssh,这时最好新建一个备份用户,并且配置 sshd仅允许这个用户通过RSA认证方式进入。如果服务器在防火墙内,则最好限定客户端的IP地址,拒绝其它所有连接。如果客户机在防火墙内,则可以简单允许防火墙打开TCP端口22ssh外发连接就ok了。

 

Q:我能将更改过或者删除的文件也备份上来吗?

A:当然可以:

 

你可以使用如:rsync -other -options -backupdir = ./backup-2000-2-13 ...这样的命令来实现。

这样如果源文件:/path/to/some/file.c改变了,那么旧的文件就会被移到./backup-2000-2-13/path/to/some/file.c

这里这个目录需要自己手工建立起来

 

Q:我需要在防火墙上开放哪些端口以适应rsync

A:视情况而定

 

rsync可以直接通过873端口的tcp连接传文件,也可以通过22端口的ssh来进行文件传递,但你也可以通过下列命令改变它的端口:

 

rsync --port 8730 otherhost::

或者

rsync -e 'ssh -p 2002' otherhost:

 

Q:我如何通过rsync只复制目录结构,忽略掉文件呢?

Arsync -av --include '*/' --exclude '*' source-dir dest-dir

 

Q:为什么我总会出现"Read-only file system"的错误呢?

A:看看是否忘了设"read only = no"

 

Q:为什么我会出现'@ERROR: invalid gid'的错误呢?

Arsync使用时默认是用uid=nobody;gid=nobody来运行的,如果你的系统不存在nobody组的话,就会出现这样的错误,可以试试gid = nogroup或者其它

 

Q:绑定端口873失败是怎么回事?

A:如果你不是以root权限运行这一守护进程的话,因为1024端口以下是特权端口,会出现这样的错误。你可以用--port参数来改变。

 

Q:为什么我认证失败?

A:从你的命令行看来:

 

你用的是:

>; bash$ rsync -a 144.16.251.213::test test

>; Password:

>; @ERROR: auth failed on module test

>;

>; I dont understand this. Can somebody explain as to how to acomplish this.

>; All suggestions are welcome.

 

应该是没有以你的用户名登陆导致的问题,试试rsync -a [email protected]::test test