Sync SVN repository with remote FTP server
19 01 2009This script was written for the company I work for well over a year ago, but I just decided to release it to the public now. It has been in use all of this time and is still in use now, so that should tell you that it's a pretty reliable script. Any bugs we encountered over the course of using this program have been fixed. Hopefully you'll have the same luck as us.
Basics:
This script is run as a SVN hook (post-commit). After committing changes to your subversion repository, this script is invoked and synchronization begins. The script creates a local copy of the repository, and files just committed are sent via FTP.
Usage:
One copy of the script can be used for an unlimited number of repositories, so the script can be placed in a globally-available location. In our scenario, we placed the script at /usr/local/bin/svn2ftp.sh . There are four command-line arguments to the script that are required. The first two arguments can be kept the same as below, as they're passed to the script by subversion. The third parameter is the path between the repository and the trunk (e.g., if your SVN path is http://<host>/svn/repo/dir/trunk, then you'd put "dir" as the parameter; otherwise, you'd put "." if there's no directory in between). The fourth parameter is the full path to the config file of the repo. A sample to put in repo/hooks/post-commit:
DATE=`date +'%m-%d-%Y'`
/usr/local/bin/svn2ftp.sh "$REPOS" "$REV" "." "/svn2ftp/conf/repo.conf" >> /svn2ftp/logs/repo-$DATE.log
We have our directory structure as follows, but you can change it as you please:
/svn2ftp/conf # Where config files are stored
/svn2ftp/logs # Where log files are stored
/svn2ftp/repos # Where raw repo contents are stored
A sample config file can be found below.The code:
I initially wrote this program using the Linux 'ftp' program. It works well and all, but if I encounter server or any other errors, the program still exits with a successful error code. This was a bummer in our situation, so I wrote an FTP client in PHP that reports errors correctly. When an error is encountered, files that were not uploaded successfully will be retried upon the next commit. Links to both versions, as well as the config file, are below:
Categories : Linux Luvin'
Trackbacks : No Trackbacks »

Trackbacks
No Trackbacks