你的位置:首页 > 操作系统

[操作系统]svn利用钩子post

创建一个新的版本库:

[[email protected] svn]# pwd/home/svn[[email protected] svn]# svnadmin create webtest[[email protected] svn]# tree webtest/webtest/├── conf│   ├── authz│   ├── passwd│   └── svnserve.conf├── db│   ├── current│   ├── format│   ├── fsfs.conf│   ├── fs-type│   ├── min-unpacked-rev│   ├── rep-cache.db│   ├── revprops│   │   └── 0│   │     └── 0│   ├── revs│   │   └── 0│   │     └── 0│   ├── transactions│   ├── txn-current│   ├── txn-current-lock│   ├── txn-protorevs│   ├── uuid│   └── write-lock├── format├── hooks│   ├── post-commit.tmpl│   ├── post-lock.tmpl│   ├── post-revprop-change.tmpl│   ├── post-unlock.tmpl│   ├── pre-commit.tmpl│   ├── pre-lock.tmpl│   ├── pre-revprop-change.tmpl│   ├── pre-unlock.tmpl│   └── start-commit.tmpl├── locks│   ├── db.lock│   └── db-logs.lock└── README.txt10 directories, 28 files

 再建一个工作副本:

[[email protected] www]# pwd/alidata/www[[email protected] www]# mkdir webtest[[email protected] www]# #授权:否则提交会报权限错误![[email protected] www]# chmod -R 777 webtest/

配权限:

[[email protected] conf]# vi svnserve.conf
[general]### These options control access to the repository for unauthenticated### and authenticated users. Valid values are "write", "read",### and "none". The sample settings below are the defaults.anon-access = readauth-access = writepassword-db = /home/svn/webtest/conf/passwdauthz-db = /home/svn/webtest/conf/authz
[[email protected] conf]# vi passwd
[users]
# harry = harryssecret
# sally = sallyssecret
svnadmin = 123456
test = 123456
[[email protected] webtest]# vi /home/svn/webtest/conf/authz
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
admin = svnadmin
user = test
[/]
@admin = rw
[/webtest]
@admin = rw
* =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r

 

[[email protected] webtest]# ps -ef |grep svn
root      2586     1  0 13:33 ?        00:00:00 svnserve -d -r /home/svn/webtest/
root      2590  2475  0 13:33 pts/0    00:00:00 grep svn

进入该目录后,checkout出一个副本,用于同步上线上服务器的路径:

[[email protected] www]# svn co svn://192.168.1.72/webtestsvn: URL 'svn://192.168.1.72/webtest' doesn't exist

 

[[email protected] www]# ls /home/svn/test webtest #有两个版本库启动的时候应该是:svnserve -d -r /home/svn/

 

[[email protected] www]# ps -ef|grep svnroot   2650   1 0 14:00 ?    00:00:00 svnserve -d -r /home/svn/root   2678 2475 0 14:04 pts/0  00:00:00 grep svn

 

[[email protected] www]# svn co svn://192.168.1.72/webtestChecked out revision 0.[[email protected] www]# lsphpwind sx webtest xxzz

 配WEB:

我这里是开一个nginx vhost

[[email protected] vhosts]# vi webtest.conf
server {
        listen       83;
        server_name  localhost;
        index index.html index.htm index.php;
        root /alidata/www/webtest;
        location ~ .*\.(php|php5)?$
        {
                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
                expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
                expires 1h;
        }
       
        include /alidata/server/nginx/conf/rewrite/default.conf;
        access_log  /alidata/log/nginx/access/webtest.log;
}

 

[[email protected] vhosts]# service nginx reloadReloading nginx!

 

[[email protected] hooks]# cp post-commit.tmpl post-commit
[[email protected] hooks]# which svn
/usr/bin/svn

 

[[email protected] hooks]# vi post-commit[[email protected] hooks]# pwd/home/svn/webtest/hooksREPOS="$1"REV="$2"SVN=/usr/bin/svnWEB=/alidata/www/webtestRSYNC=/usr/bin/rsyncLOG=/tmp/rsync_web.logWEBIP=192.168.1.73#这是线上web服务器IPexport LANG=en_US.UTF-8$SVN update $WEB --username svnadmin --password 123456if [ $? == 0 ]echo "" >>$LOGecho `date` >> $LOGecho "#####################" >>$LOG$RSYNC -vaztpH --timeout=90 --exclude-from=/home/svn/webtest/exclude.list $web root@$WEBIP:/www/>>$LOGif#--exclude-from 可不要根据需求不同步的排除
[[email protected] hooks]# chmod +x post-commit

 http://darkyin.blog.51cto.com/6260426/1361132