1 2 |
|
post-receive还得是这个,如果改成git --work-tree=$web_dir checkout -f,去git拉取代码好像都不是最新的,慎重
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
有时候,不需要定时同步。
参考上面的链接
#!/bin/sh
cur_dir=$(pwd)
web_dir=/opt/webroot/gitlab_hook/
#echo $cur_dir"/hooks" > /tmp/gitlab_hook_cur_dir.txt
#echo `whoami` > /tmp/gitlab_hook.txt
GIT_WORK_TREE=$web_dir git checkout -f
$cur_dir"/hooks/web_rsync" $web_dir > /tmp/gitlab_hook_rsync.log
web_rsync
#!/bin/bash
#ROOT="/data/www/wwwroot/bbs.linuxtone.org/"
SITE="xx"
USER="root"
PASSWORD="xx"
RSYNC_OPTS="-e \\\"ssh -p22 -o StrictHostKeyChecking=no\\\" -azuv --progress --exclude ".git" --bwlimit=150 --timeout=1200 -l"
auto_rsync() {
expect -c "eval spawn -noecho rsync $RSYNC_OPTS $1 $2
expect \"*?assword:*\"
send -- \"$PASSWORD\r\"
expect eof"
}
sync() {
FILE=$(basename $1)
DEST=$(dirname $1)
SRC=$1
# download remote site file to current location
#auto_rsync $USER@$SITE:$ROOT$FILE $DEST
auto_rsync $SRC $USER@$SITE:$DEST
# update remote site file if newer than backup
#auto_rsync $1 $USER@$SITE:$ROOT
}
# Remote file Directory
sync "/home/post-receive"
本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/1775314,如需转载请自行联系原作者