How to Export and Import a Subversion Repository: A Comprehensive Guide

When working on software projects, maintaining a clear and efficient source code management system is crucial. For developers using Subversion (SVN), there may come a time when you need to relocate your repository—such as when ending a commercial SVN account after a project completion. How do you export and then import your Subversion repository while retaining the history and integrity of your data? In this blog post, we will address this common concern and provide you with a step-by-step guide to accomplish this task seamlessly.

Understanding the Basics of SVN Repository Migration

Before diving into the actual process, let’s clarify some essential concepts related to SVN:

  • Repository: A storage structure for your codebase that contains all versions and history of your project.
  • Filesystem Access: The ability to read and write files directly on the server where your repository is hosted.
  • Backends in SVN: Subversion can utilize different backend storage methods, the most common being FSFS and Berkeley DB.

In many situations, you may need filesystem access on both the current and new host to facilitate a smooth transition.

Moving Your Repository: The Process Explained

1. Check Your Backend

Firstly, ascertain the backend your current repository employs. You can determine if your repository is using FSFS (the default for recent versions) or Berkeley DB through commands or by checking your server setup.

2. Use Filesystem Copy for FSFS

If you find that you are using FSFS, the simplest method to migrate your repository is to:

  • Make a Filesystem Copy: Directly copy the entire directory containing your repository to the new host. This will include all history and data.

3. Utilize svnadmin dump and svnadmin load for Berkeley DB

When dealing with Berkeley DB, or if you are uncertain about your backend, follow these steps:

  • Dump the Old Repository:

    svnadmin dump /path/to/old/repository > repository_dump.svn
    

    This command creates a single file that captures all revisions and history, which you’ll transfer to the new server.

  • Create a New Empty Repository:

    svnadmin create /path/to/new/repository
    
  • Load the Dump into the New Repository:

    svnadmin load --force-uuid /path/to/new/repository < repository_dump.svn
    

    Using the --force-uuid option will ensure that the repository’s unique identifier (UUID) is compatible for use in the new location, allowing users to switch their working copies without issues.

4. Handle Absence of Filesystem Access

In scenarios where filesystem access is not permissible, alternative solutions may exist, such as third-party tools or scripts. The process would typically involve:

  • Replaying Each Revision: Using svn log to recreate commits on the new repository.
  • Fixing Metadata: Configuring pre-revprop-change and post-revprop-change hook scripts properly to maintain data integrity.

If keeping the history isn’t a priority, a simpler option is to import from your working copy to the new repository. However, this will discard the historical revisions, which might be undesirable in most situations.

Conclusion

Exporting and importing a Subversion repository may seem daunting at first, but by following these clearly outlined steps, you can successfully move your repository while preserving its history. Whether you are using filesystem copy techniques for FSFS or utilizing the svnadmin dump/load commands for Berkeley DB, you’ve now equipped yourself with the knowledge required to tackle repository migrations confidently.

By ensuring proper backend checks and utilizing the necessary command-line tools, you can transfer your valuable project data without losing any history or integrity. If you have additional questions or need further assistance, don’t hesitate to reach out to the community or relevant forums. Happy coding!