# SVN钩子脚本简介
> 钩子脚本的具体写法就是操作系统中shell脚本程序的写法,根据自己在svn所在的操作系统和shell程序进行相应的开发。
默认情况下,钩子的子目录中包含了各种版本库钩子模版
**查看钩子文件夹列表**
~~~
$ ls -lh /var/www/svn/svndata/app/hooks/
总用量 36K
-rw-r--r--. 1 root root 2.0K 10月 14 09:01 post-commit.tmpl
-rw-r--r--. 1 root root 1.6K 10月 14 09:01 post-lock.tmpl
-rw-r--r--. 1 root root 2.3K 10月 14 09:01 post-revprop-change.tmpl
-rw-r--r--. 1 root root 1.6K 10月 14 09:01 post-unlock.tmpl
-rw-r--r--. 1 root root 3.4K 10月 14 09:01 pre-commit.tmpl
-rw-r--r--. 1 root root 2.4K 10月 14 09:01 pre-lock.tmpl
-rw-r--r--. 1 root root 2.8K 10月 14 09:01 pre-revprop-change.tmpl
-rw-r--r--. 1 root root 2.1K 10月 14 09:01 pre-unlock.tmpl
-rw-r--r--. 1 root root 2.8K 10月 14 09:01 start-commit.tmpl
~~~
>**svn的hooks模版功能介绍**
start-commit 提交前触发事务
**pre-commit 提交完成前触发事务**
**post-commit 提交完成时触发事务**
pro-revprop-change 版本属性修改前触发事务
post-revprop-change 版本属性修改后触发事务
post-lock 对文件进行加锁操作之后执行该脚本
## 实例
chmod 755 post-commit && vim post-commit
~~~
#!/bin/sh
# POST-COMMIT HOOK
REPOS="$1"
REV="$2"
#mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf
export LANG=zh_CN.UTF-8
####### 导出到本地临时文件夹,为同步到其他服务器做准备 #########
svn update /opt/svn_rsync/eduask --no-auth-cache --non-interactive --force --username=rsyncsvn --password=123456 >> /tmp/eduask_hooks.txt 2>&1
###### 导出到远程其他服务器 #########
#export RSYNC_PASSWORD='gp_3001e3006ea'
##### 导出到 192.168.0.61 #######
#rsync -rvt --delete --progress --ignore-errors --exclude ".svn/" /opt/svn_messages_system_rsync/ backupgp@192.168.0.61::messages_demo
rsync -rvt --delete --progress --ignore-errors --exclude ".svn/" --exclude "/jt_eduask/Runtime/" --exclude "/laodao_eduask/Uploads/" /opt/svn_rsync/eduask/ /var/www/html/eduask/ >> /tmp/rsync_svn.txt 2>&1
chown apache:apache -R /var/www/html/eduask
~~~