It is not save to have SVN repository to host the web files directly because web user can see the .svn folder which contains all the metadata, source code, structure and many more. My PHP programmers want to test the website in the internal web server directly. In this case, I will need to export the SVN repository into public_html directory (the HTTP document root) so they can see the changes they made in their source code.
The following script will export the SVN to a temporary folder, then from that temporary folder, it will use rsync append method to replace/remove any files associated with the temporary SVN directory. This will make sure the public_html will sync to the SVN directory faster.
Variable I use as below:
OS: CentOS 6.0 64bit
SVN URL: svn://192.168.100.100/svnrepo/web/php
Web directory: /home/user/public_html
Web URL: http://192.168.100.100/
1. Create the script:
$ touch /root/svn_export
2. Paste following code and change to the appropriate value:
# !/bin/bash # SVN exporter from Subversion repository to web directory HOMEDIR='/home/user' SVNHOST='192.168.100.100' SVNURL='svnrepo/web/php' SVNUSER='exporter' SVNPASS='expass123' PUBLIC_HTML='/home/user/public_html' rm -Rf $HOMEDIR/svnexport.temp svn export svn://$SVNHOST/$SVNURL --username $SVNUSER --password $SVNPASS $HOMEDIR/svnexport.temp rm -Rf $HOMEDIR/svnexport.old mv $HOMEDIR/svnexport $HOMEDIR/svnexport.old mv $HOMEDIR/svnexport.temp $HOMEDIR/svnexport rsync -avz $HOMEDIR/svnexport/ $PUBLIC_HTML
3. Change the permission to executable:
$ chmod 755 /root/svn_exporter
4. Run the script:
5. Put it into cron job every 1 minutes:
$ crontab -e
Insert following line:
* * * * * /root/svn_exporter
6. Save the file and restart the crond service:
$ service crond restart
Done! Every one minute, the SVN repository will be exported to public_html directory and your programmer can test it online via http://126.96.36.199.