First you’ll need to follow the SVN wiki entry to set up svn repository and passwordless ssh access at A2Hosting.
As this is only for one user, then the easiest way is to use svn dump functionality which allows for incremental dumps. Using post-commit hooks we’ll just save the new commits since last sync to a dump file. Furthermore, apart from manual update of repositories from dump we’ll also write a script which will sync the repositories nightly(e.g using cron). But the main thing is to be able to switch from using remote(main) repository to its local copy to continue developing if for some reason we don’t have network access.
Setting up repositories
I assume that you’ve got one repository completely set up and ready. Now we only need to dump the repository,
svnadmin dump repository_path >dumpfile
copy the dumpfile and run
svnadmin create repository_path
svn load repository_path <dumpfile
Setting up automatic dumping
The next thing is installing post-commit hook, which is just an executable program put into repository_path/hooks. Consult post-commit.tmpl for more info.
post-commit
#!/bin/sh
REPOS="$1"
REV="$2"
DUMP=path_to_dump_to
svnadmin dump $REPOS --incremental --revision $REV >$DUMP/newsvn.dump
cat $DUMP/svn.dump $DUMP/newsvn.dump >$DUMP/svn_.dump
mv -f $DUMP/svn_.dump $DUMP/svn.dump
And don’t forget to make it executable with chmod.
Synchonizing the repositories
This is the script to sync from remote to local
sync2local
#!/bin/bash
FTP_USER=
FTP_PASS=
FTP_SERVER=
SSH_SERVER=
SSH_USER=
DUMPFILE=svn.dump
REPO=/svn
PORT=-p 7822
#delete old dump file
if [ -e $DUMPFILE ]; then
rm $DUMPFILE
fi
#get current dump file
wget --password=$FTP_PASS --user=$FTP_USER ftp://$FTP_SERVER/$DUMPFILE
if [ $? != 0 ]; then
echo No dumpfile available
exit
fi
#update local repository
svnadmin load $REPO <$DUMPFILE
#delete dump file if sucessful
if [ -e $DUMPFILE ]; then
ssh $SSH_USER@$SSH_SERVER $PORT rm $DUMPFILE
rm $DUMPFILE
fi
And the script to sync from local to remote
sync2remote
#!/bin/bash
FTP_USER=
FTP_PASS=
FTP_SERVER=
SSH_SERVER=
SSH_USER=
PORT="-p 7822"
REPO=
#dumpfile with full path
DUMPFILE=
#test if dump file exists
if [ ! -e $DUMPFILE ]; then
echo "No dump file available"
exit
fi
#upload dump file
echo "put $DUMPFILE $(basename $DUMPFILE)" | ftp ftp://$FTP_USER:$FTP_PASS@$FTP_SERVER
if [ $? != 0 ]; then
echo "Can't upload dumpfile"
exit
fi
#update remote repository
ssh $SSH_USER@$SSH_SERVER $PORT "svnadmin load $REPO <$(basename $DUMPFILE)"
#delete dump file if sucessful
rm $DUMPFILE
ssh $SSH_USER@$SSH_SERVER $PORT rm $(basename $DUMPFILE)
Switching between repositories
These 2 scripts svn2remote and svn2local can be used to switch a working copy between repositories. Before switching it will sync to the most recent copy, which is precisely what we need.
svn2remote
#!/bin/bash
REPO=/svn
sync2remote
svn switch --relocate file://$REPO svn+a2hosting://zedr0n@quant0r.com/home/zedr0n/svn .
svn2local
#!/bin/bash
REPO=/svn
sync2local
svn switch --relocate svn+a2hosting://zedr0n@quant0r.com/home/zedr0n/svn file://$REPO .
So, basically, whenever you want to work on some projects, you just check it out by doing svn2local and merge the changes with svn2remote when you are done. If you are confident in remote repository then you can just work with it all the time. It’s quite flexible really…