下载:rsync-3.1.1.tar.gz
wget https://download.samba.org/pub/rsync/src/rsync-3.1.1.tar.gz
安装:(没有其他依赖包,如果有的话,ssh算是一个)
$ ./configure
$ make
# make install
示例:
rsync -avzhe ssh --progress --delete --exclude-from=/root/exclude.list [email protected]:/usr/local/mysql/data/ /usr/local/mysql/data/
--exclude=PATTERN exclude files matching PATTERN
--exclude-from=FILE read exclude patterns from FILE
--include=PATTERN don't exclude files matching PATTERN
--include-from=FILE read include patterns from FILE
exlude.list内容:
auto.cnf
ib_logfile1
ibdata1
ib_logfile0
mysql
mysql.sock
node0.err
node0.pid
test
其中有文件夹,文件名,每行一个。置于exclude之后,排除列出的多个文件,不进行传送。
rsync作为daemon 服务运行配置:
服务端:
配置/etc/rsyncd.conf:
uid=root
gid=root
use chroot=no
max connections=200
timeout=600
stirict modes=yes
port=873
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
log file=/var/log/rsynsd.log
[app]
path=/home/backuper/app
comment =svn for me to test
ignore errors
read only =false
hosts allow =192.168.1.10
hosts deny=0.0.0.0/32
auth users=lwx123
secrets file=/etc/rsync.password
设置用户密码文件:
/etc/rsync.password
lwx123:lwx123
启动:rsync --daemon --config=/etc/rsyncd.conf
也可以使用xinetd管理rsync的启动与关闭:
编辑: /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no
flags = IPv6
socket_type = stream
port = 12000
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
/etc/init.d/xinetd restart
客户端:
设置密码文件
/etc/rsync.password
lwx123
rsync -vzrtopg --progress --exclude=.svn --delete /home/lwx/app [email protected]3::app --password-file=/etc/rsync.password
同步脚本:vi test.sh
#!/bin/bash
sudo /usr/bin/svn update --username lwx --password lwx123 /home/lwx/app
if [ $? -eq 0 ]
then
echo "" >> ${Log}/svn-update.log 2>&1
echo `date + '%F %T'` >>${Log}/svn-update.log 2>&1
echo "----------------------------------------------" >>${Log}/svn-update.log 2>&1
sudo chown -R apache.apache /home/lwx/app
sudo /usr/bin/rsync -vzrtopg --progress --exclude=.svn --delete /home/lwx/app [email protected]::app --password-file=/etc/rsync.password
fi
修改vim /etc/sudoers(对运行svn的apache用户进行临时提权)
增加如下行:
User_Alias APACHE = apache, mikem
Cmnd_Alias FIREWALL =/usr/bin/svn,/usr/bin/rsync,/bin/chown(注意su,chown命令无效)
APACHE ALL =(ALL) NOPASSWD:FIREWALL
注释掉:#Defaults requiretty
钩子文件编辑:vi post-commit
REPOS="$1"
REV="$2"
export LANG=en_US.UTF-8
sh /home/lwx/test.sh
报错:ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1635) [sender=3.1.1]
将远程服务器设置:
setenforce 0。
命令参考:
Pull
Push
参考文档: http://linux.die.net/man/5/rsyncd.conf
https://www.atlantic.net/community/howto/setup-rsync-daemon/
https://www.atlantic.net/community/howto/use-rsync-copysync-files-servers/