当前位置: 首页 > 图文教程 > 服务器 > Windows服务器 > rsync 端口更换(默认873)

Windows服务器
Windows Server 2003 R2 Beta 2将公测
Windows 2003组策略和安全模板的应用
Windows 2003 64位正式版抢先体验
微软发布WinServer2003 R2 Beta2
Windows Server 2003 安全配置实战演习
快速关闭Windows 2003的三种方法
windows 2003服务器防止海洋木马的安全设置
制作无盘Windows 2003之无忧Ghost文件
为Windows 2003加装视频压缩
安全配置向导为Win2003打造“铜墙铁壁”
用Win 2003 SP1向导功能打造安全服务器
在Win 2003系统中挖掘免费刻录软件
Windows 2003优化系列之系统服务的开关
发扬DIY精神 为Windows 2003移植系统还原
活学活用Win2003分区增容功能
轻松管理Win 2003的“远程桌面”
自动管理Windows 2003好用的“远程桌面”
活学活用Windows Server 2003分区增容功能
使用Web接口远程维护Win2003服务器
教你一招:Windows2003系统优化大有玄机

Windows服务器 中的 rsync 端口更换(默认873)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-04   浏览: 615 ::
收藏到网摘: n/a

用rsync对网站进行镜像备份 一般使用默认端口的话, 在服务端的启动命令为:
/usr/bin/rsync --address=192.168.1.23 --daemon
如果在客户端需要换另外的端口侦听, 则使用
/usr/bin/rsync --address=172.18.16.89 --port=8081 --daemon
客户端命令:
/usr/bin/rsync -vzrc --progress --bwlimit=300 /usr/local/tomcat/webapps/.gif 172.18.16.89::appLogo/
rsync: failed to connect to 172.18.16.89: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(107) [sender=2.6.8]

此时在客户端也必须指定端口, 不然会报错。
改为
/usr/bin/rsync -vzrc --port=8081 --progress --bwlimit=300 /usr/local/tomcat/webapps/.gif 172.18.16.89::appLogo/
就OK
用rsync对网站进行镜像备份
三、FAQ
Q:如何通过ssh进行rsync,而且无须输入密码?
A:可以通过以下几个步骤
1. 通过ssh-keygen在server A上建立SSH keys,不要指定密码,你会在~/.ssh下看到identity和identity.pub文件
2. 在server B上的home目录建立子目录.ssh
3. 将A的identity.pub拷贝到server B上
4. 将identity.pub加到~[user b]/.ssh/authorized_keys
5. 于是server A上的A用户,可通过下面命令以用户B ssh到server B上了
e.g. ssh -l userB serverB
这样就使server A上的用户A就可以ssh以用户B的身份无需密码登陆到server B上了。
Q:如何通过在不危害安全的情况下通过防火墙使用rsync?
A:解答如下:
这通常有两种情况,一种是服务器在防火墙内,一种是服务器在防火墙外。
无论哪种情况,通常还是使用ssh,这时最好新建一个备份用户,并且配置sshd仅允许这个用户通过RSA认证方式进入。
如果服务器在防火墙内,则最好限定客户端的IP地址,拒绝其它所有连接。
如果客户机在防火墙内,则可以简单允许防火墙打开TCP端口22的ssh外发连接就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只复制目录结构,忽略掉文件呢?
A:rsync -av --include '*/' --exclude '*' source-dir dest-dir
Q:为什么我总会出现"Read-only file system"的错误呢?
A:看看是否忘了设"read only = no"了
Q:为什么我会出现'@ERROR: invalid gid'的错误呢?
A:rsync使用时默认是用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
四、一些可借鉴的脚本
这里这些脚本都是rsync网站上的例子:
1、每隔七天将数据往中心服务器做增量备份
#!/bin/sh
# This script does personal backups to a rsync backup server. You will end up
# with a 7 day rotating incremental backup. The incrementals will go
# into subdirectories named after the day of the week, and the current
# full backup goes into a directory called "current"
# [email protected]
# directory to backup
BDIR=/home/$USER
# excludes file - this contains a wildcard pattern per line of files to exclude
EXCLUDES=$HOME/cron/excludes
# the name of the backup machine
BSERVER=owl
# your password on the backup server
export RSYNC_PASSWORD=XXXXXX

########################################################################
BACKUPDIR=`date +%A`
OPTS="--force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES
--delete --backup --backup-dir=/$BACKUPDIR -a"
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
# the following line clears the last weeks incremental directory
[ -d $HOME/emptydir ] || mkdir $HOME/emptydir
rsync --delete -a $HOME/emptydir/ $BSERVER::$USER/$BACKUPDIR/
rmdir $HOME/emptydir
# now the actual transfer
rsync $OPTS $BDIR $BSERVER::$USER/current
2、备份至一个空闲的硬盘
#!/bin/sh
export PATH=/usr/local/bin:/usr/bin:/bin
LIST="rootfs usr data data2"
for d in $LIST; do
mount /backup/$d
rsync -ax --exclude fstab --delete /$d/ /backup/$d/
umount /backup/$d
done
DAY=`date "+%A"`
rsync -a --delete /usr/local/apache /data2/backups/$DAY
rsync -a --delete /data/solid /data2/backups/$DAY
3、对vger.rutgers.edu的cvs树进行镜像
#!/bin/bash
cd /var/www/cvs/vger/
PATH=/usr/local/bin:/usr/freeware/bin:/usr/bin:/bin
RUN=`lps x | grep rsync | grep -v grep | wc -l`
if [ "$RUN" -gt 0 ]; then
echo already running
exit 1
fi
rsync -az vger.rutgers.edu::cvs/CVSROOT/ChangeLog $HOME/ChangeLog
sum1=`sum $HOME/ChangeLog`
sum2=`sum /var/www/cvs/vger/CVSROOT/ChangeLog`
if [ "$sum1" = "$sum2" ]; then
echo nothing to do
exit 0
fi
rsync -az --delete --force vger.rutgers.edu::cvs/ /var/www/cvs/vger/
exit 0
4、利用find的一种巧妙方式
rsync -avR remote:'`find /home -name "*.[ch]"`' /tmp/
可以用这种方法列出需要备份的文件列表——这种方法似乎比较少人用到。
五、参考资料:
1、http://rsync.samba.org/
2、rsync examples
3、rsync FAQ