rsync 主页 http://rsync.samba.org/
使用ssh 传输rsync 流量具有下述优点:可通过网络加密数据,也可利用使用ssh 客户端密钥建立的任何信任关系。如果要在两台计算机之间保持大型、复杂目录结构的同步性(尤其是两者间的差异很小时),那么rsync 就是一种使用起来极为方便(并且执行速度很快)、随心所欲的工具。
参数:
-e "ssh -p 2234"
录,那就不会从目标副本中删除这些文件和目录。要精确保存副本,须
包含 标志:
root@rover:~# rsync -ave ssh greendome:/home/ftp/pub/ /home/ftp/pub/
实例:
rsync -avze ssh /home/me/public_html/contents/ user@toku:/home/tenten/contents/
Shell 例子:
#!/bin/sh# -------- sync_contents.sh ----------
# Synchronization for user contents.
# This program is copyright (c) 2006
# Kreny
# Ver. 1.0.0 2006/8/3 16:53:30
## Date for logging
DATE=`date +'%Y-%m-%d %T'`# Log file full pathname
LOG_FILE='/home/user/rsync_contents.log'if [ ! -f $LOG_FILE ]; then
echo "ERROR:"
echo "Please check whether the log file $LOG_FILE exists and the writting permission."
exit
fi# Contents path in original Server. No backslash at the end of the path.
CONTENTS_PATH_ORGINAL='/homeuser/public_html/contents'# Contents path in target Server. Enter the backslash at the end of the path.
CONTENTS_PATH_TARGET='/homeuser/public_html/'# Target server list
TARGET_SERVER='toku toku toku'# ssh login username
USER_NAME='user'# rsync 's path
RSYNC='/usr/bin/rsync'echo "----------- $DATE -----------" >> $LOG_FILE
for cur_server in $TARGET_SERVER
do
echo "Synchronization for Server $cur_server ..." >> $LOG_FILE
$RSYNC -zave ssh $CONTENTS_PATH_ORGINAL $USER_NAME@$cur_server:$CONTENTS_PATH_TARGET >> $LOG_FILE
doneecho "----------- END -----------" >> $LOG_FILE
参考资料: