Part of the process of moving away from my old, potentially-hard-to-maintain-in-the-future project-publishing model involved moving my local SVN repositories to Google Code, Google’s open-source-friendly project-hosting service.
Setting up the project pages and moving my existing code over there was quite easy. However, I wanted to keep local read-only repositories to avoid breaking links while I get uguu.ca set up for future development work and because I like having redundant backups of things I consider important.
I figured I should kick this blog off with a post that others might consider helpful, so I’m documenting the actions I took below. Note that this will not preserve SVN UUIDs, so you’ll need to diff and patch any dirty working copies you or other committers may have or otherwise adapt the steps to suit your needs. I’m also assuming you’ve set up sudo. If not, do everything post-committing-to-Google as a user, like root, who has permissions that will prevent other users from being able to touch the mirror repository (only svnsync should ever be allowed to write to it, and you’ll be crontabbing that).
- Create and reset your Google Code repository
- Create a Google Code project
- Find and follow the “reset” link at the bottom of any page under the “source” tab
- Migrate your existing code to Google Code
svnsync init https://YOUR_PROJECT_NAME.googlecode.com/svn EXISTING_REPOSITORY
- You’ll be prompted to provide credentials to commit to Google Code; these can be found in your profile
- If your old repository requires credentials to be read, you may also be prompted for those
svnsync sync --non-interactive https://YOUR_PROJECT_NAME.googlecode.com/svn
- Wait while each commit is played out; if you have mature projects, this can take quite a while. Do NOT interrupt this process or you may be left with a locked repository on Google’s end, which you’ll need to handle manually (either by clearing the lock or resetting the repository again)
- At this point, everything you’ve ever done has been duplicated on Google’s side, so it’s time to create the local mirror to make sure that, in the unlikely event that Google suddenly disappears, you’ll still have access to your work
- Before proceeding, it would be a good idea to grab a fresh checkout of your code from Google’s servers and make sure it matches your working copy, using diff and ignoring the .svn subpaths.
- When satisfied that nothing was lost in the move, you may want to delete your old repository to avoid confusion; you can’t, using this method, just have it sync against Google’s repositories as-is (UUID mismatch); additionally, after remaking the repository, the same UUID-mismatch problem will prevent committers from updating a non-master repository, so this is a good thing
- Create a new repository to house code mirrored from Google Code
sudo svnadmin create NEW_REPOSITORY_PATH
- NEW_REPOSITORY_PATH should be specified in absolute terms, just to avoid confusion later
sudo bash -c 'echo "#!/bin/bash" > NEW_REPOSITORY_PATH/hooks/pre-revprop-change'
sudo chmod u+x NEW_REPOSITORY_PATH/hooks/pre-revprop-change
- This avoids an error normally raised to prevent accidental damage to repositories
- The command in step 2 may look a little funny — this is because the redirect needs to be caught within the scope of sudo, so the whole thing needs to be passed as a single argument to a new bash instance
- Synchronize your repository with the one on Google’s servers
sudo svnsync init file://NEW_REPOSITORY_PATH http://YOUR_PROJECT_NAME.googlecode.com/svn
- Note that you’ll have something that looks like ‘file:///var/svn/my_project’ here, with three forward slashes
sudo svnsync sync --non-interactive file://NEW_REPOSITORY_PATH
- Set up a cron job to keep things synchronized every night
sudo crontab -e
0 3 * * * svnsync sync --non-interactive file://NEW_REPOSITORY_PATH
- Adding this line will make your system synchronize the repository with Google’s servers every day at 3:00 AM; the first two values are minute and hour, so play with them as you see fit
- Everything’s done! Your code’s now on Google’s highly accessible servers, and surrounded by Google’s excellent project-management resources, and you have a local copy for paranoia’s sake