How do I migrate an SVN repository to another SVN

2019-01-16 05:10发布

问题:

Is there a simple way to copy a directory from one repository into another repository with copying all of the history?

回答1:

The simplest way is using:

svnadmin dump path/to/repos > repos.out

This will create a portable format for your repository (with history) in the file repos.out. You can then use

svnadmin load path/to/newrepos < repos.out

to load your 'dumped' repository to the new or existing one.

Chapter 5. Repository Maintenance -> Migrating Repository Data Elsewhere has this note about using svnadmin dump as of version 1.7:

The Subversion repository dump format describes versioned repository changes only. It will not carry any information about uncommitted transactions, user locks on filesystem paths, repository or server configuration customizations (including hook scripts), and so on.



回答2:

As suggested in the Subversion book:

svnadmin dump path/to/repos_src \
    | svndumpfilter include path/inside/svn/to/directory \
    | svnadmin load path/to/repos_dst

With an example:

svnadmin dump /var/lib/svn/old_repo \
    | svndumpfilter include trunk/my_project/common_dir \
    | svnadmin load /var/lib/svn/new_repo


回答3:

If you don't want history, you can use svn export to get a clean folder without the .svn folders and then svn import into your other repository.

With history, you would need to use the svnadmin dump. You would then use svndumpfilter to filter for only the parts or paths you want to use before using svnadmin load.

Topics to read:

  • Migrating Repository Data Elsewhere
  • Filtering Repository History


回答4:

Use the svnsync — Subversion Repository Mirroring command:

svnsync is the Subversion remote repository mirroring tool. Put simply, it allows you to replay the revisions of one repository into another one.

The Subversion documentation for the svnsync command has the following warning (as of version 1.7) implying that once some other SVN commands are used to modify a mirror repository, svnsync should not be used with that particular mirror again:

svnsync is very sensitive to changes made in the mirror repository that weren't made as part of a mirroring operation. To prevent this from happening, it's best if the svnsync process is the only process permitted to modify the mirror repository.



回答5:

You can create a dump file using svnadmin dump, then import to a new repository with svnadmin load.



回答6:

In Subversion version 1.7 there is a new command, svnrdump which can be used to access a remote repository and generate the same dump format output as is generated by the svnadmin dump command. This allows you to use svnrdump with svnadmin load to transfer a Subversion repository.

See svnrdump—Remote Subversion Repository Data Migration which has an explanation of the new command.

In Chapter 5 of the red book, the section Migrating Repository Data Elsewhere has a sub-section Repository data migration using svnrdump that mentions:

The primary difference [between svnrdump and svnadmin dump] is that instead of requiring direct access to the repository, svnrdump operates remotely, using the very same Repository Access (RA) protocols that the Subversion client does. As such, you might need to provide authentication credentials. Also, your remote interations [sic] are subject to any authorization limitations configured on the Subversion server.

I would also assume that the limitations of svnadmin dump concerning server configuration customizations such as hooks may not be transferred would also apply to svnrdump.



回答7:

I think it should be stated that the dump file created by utilizing

    svnadmin dump path/to/repos > dumpfile

can be created (from svn 1.7 and forth) using the command

   svnrdump dump url_to_repos > dumpfile

This is useful when done from a remote computer and not the server.



回答8:

In case this helps others, there is svn2svn to replay changesets from one Subversion repository to another:

https://github.com/tonyduckles/svn2svn



回答9:

To migrate the repository from one server to another version following are the steps you need to follow.

Step 1: Dump all the repository versions into a dump file. You might be having thousands of versions in the existing repository. So you can create a dump file using the following script.

dump.sh

# Here “i” is the version starting number, and “j” is the maximum version number of your existing #repository.
j=4999;
for ((i=0;i<=$j;i++));
do
   # your-unix-command-here
   echo $i
   svnadmin dump <old_server_repository_location > -r $i  –incremental > <dump_location>/$i.dump
done

In the above script you might get a complete dump of the old repository depending on the space availability, or you can take the dump in a short interval (i.e. from 0-5000, then from 5001-10000 and so on).

Step 2: Execute the above script using the below command. Depending on the kernel version you need to execute either of the below two queries.

$ bash dump.sh > stdout.sh
$ ./sh dump.sh > stdout.sh

This will write all the commands you had to execute using the above command into stdout.sh file. You can track this file for your future reference.

Step 3: Check if the firewall is open for port number 22 between the old and the new server. If that is not open, then ask your administrator to make this available.

Step 4: Now copy all the dump files generated from the old SVN repository to the new server using the below command.

$ sftp xxxx@<new_server>
Connecting to <new_server>…
Password:
sftp> mput *.dump <new_server>/dump_location

In the above command, xxxx is the user who is doing the operation. In the process of doing sftp you are copying the dump files from the old server to the new server.

Step 5: Create a new repository to the new Server

$ svnadmin create <new_repository>

Step 6: Now use the below script to load all the dump files.

load.sh

# Here “i” is the version starting number, and “j” is the maximum version number of your existing #repository.
j=4999;
for ((i=0;i<=$j;i++));
do
   # your-unix-command-here
   echo $i
   svnadmin load –bypass-prop-validation <new_repository> < dump_location /$i.dump
done

Just following the above six simple steps you will be able to migrate your existing repository to a new repository. Through this process you do not need to worry about the corrupted revisions of your existing repository.