Tuesday, December 10, 2013

SVN - How to dump one project out of a SVN repository

Since Subversion stores your versioned history using binary differencing algorithms and data compression (optionally in a completely opaque database system), attempting manual tweaks is unwise if not quite difficult, and at any rate strongly discouraged. And once data has been stored in your repository, Subversion generally doesn't provide an easy way to remove that data.

But there are times you need to strip out all instances of a file that was accidentally added, or you have multiple projects sharing a single repository, and you decide to split them up into their own repositories. You can use svnadmin dump and svndumpfilter to achieve this.

SVN dump file is a human-readable representation of the changes that you've made to your versioned data over time. svndumpfilter acts as a path-based filter for repository dump streams. Simply give it either a list of paths you wish to keep or a list of paths you wish to not keep, and then pipe your repository dump data through this filter.

Let assume your repository looks like:
/
   project1/
      trunk/
      branches/
      tags/
   project2/
      trunk/
      branches/
      tags/
  trunk/
      project3/

To get these three projects into their own repositories, we first dump the whole repository:
$ svnadmin dump /var/svn/repos > repos-dumpfile
* Dumped revision 0.
* Dumped revision 1.
* Dumped revision 2.
* Dumped revision 3.
…
$

Next, run that dump file through the filter, each time including only one of our top-level directories. This results in three new dump files:
$ svndumpfilter include project1 < repos-dumpfile > project1-dumpfile
…
$ svndumpfilter include project2 < repos-dumpfile > project2-dumpfile
…
$ svndumpfilter include trunk/project3 < repos-dumpfile > project3-dumpfile
…
$

Now each dumpfile only contains data for the specific project.

No comments: