Restore VisualSVN server from client copy
I am running VisualSVN on a windows VM box. The VM crashed and corrupted the image. After restoring an older image (2007) we discovered that our data backup is not functioning properly. Hence I have a bunch of projects (~20) siting on my laptop (client side) and I want to push them back into the VisualSVN Server, which is now empty.
I know this can be d开发者_运维技巧one by simply adding the project files manually, but this is going to take along time because I don't want to include every file (i.e. complied files). Any suggestions would be greatly appreciated.
Unfortunately, I don't have a fully automated solution for you but one way to figure out what files are versioned in a repository is using the list command with the command-line tool:
svn.exe list -R
That command will recursively list all files that are versioned by SVN in the current directory. Once you have that list you can copy them to another directory and batch-commit them to a new repository.
Combining that command with some Powershell magic would probably make the task of recreating the repositories as painless as possible.
Update:
I spent some time playing with Powershell and figured out how you could do this. For the example I am about to explain the original repository directory is C:\source_repos\ and the new repository directory is C:\dest_repos\.
- Open a command prompt. This can be done through the Accessories start menu folder or by running "cmd" from search box in Vista/Win7 or the Run... in WinXP.
-
From the command prompt run the following commands:
cd C:\source_repos\ echo File > filelist.csv svn.exe list -R >> filelist.csv
The second command creates filelist.csv with the first line containing the word "File". The third command runs the svn list command and redirects the output to append to filelist.csv. At this point filelist.csv should have "File" on the first line followed by every file versioned in your svn directory listed on individual lines.
-
Take the code below and paste it into a file called reposcopy.ps1:
# Assumptions / Notes: # - No crazy file names with "\" in them! # - A file named filelist.csv was created by running: # svn.exe list -R >> filelist.csv # and is in the base directory of the source repository. # - The first line of filelist.csv is "File" without quotes, this is # important for the Import-Csv command # - If you get an error about permissions when you try to run the script, # use the command "Set-ExecutionPolicy RemoteSigned" in the powershell # Source & destination repository directories $src = "C:\source_repos\" $dest = "C:\dest_repos\" # Get current directory $origdir = Get-Location # Goto source repository directory Set-Location $src # Check if destination repository directory exists, if not create it if (![IO.Directory]::Exists($dest)) { [IO.Directory]::CreateDirectory($dest) } # Import filelist.csv created with these commands at a command prompt: # cd C:\source_repos # echo File > filelist.csv # svn.exe list -R >> filelist.csv $filelist = Import-Csv filelist.csv # Go through each line in the filelist foreach ($line in $filelist) { # Concatenate the filename with the source and destination directories $srcfile = [String]::Concat($src, $line.File) $destfile = [String]::Concat($dest, $line.File) # If the destination file is a directory and it doesn't exist create it # Otherwise copy the source file to the destination. if ($destfile.EndsWith("\")) { if (![IO.Directory]::Exists($destfile)) { [IO.Directory]::CreateDirectory($destfile) } } else { Copy-Item $srcfile $destfile } } # Go back to the original directory Set-Location $origdir
You will need to modify the
$src
and$dest
variables for each run. -
Open Powershell (it can be found in Accessories on Vista/Win7 or Powershell in WinXP). Go to the directory where you saved the above script and run it. If you get an error that mentions "execution of scripts is disabled on this system", run
Set-ExecutionPolicy RemoteSigned
in the powershell to enable local scripts to run without being signed.
C:\dest_repos\
and svn add
all the files to the new repository and svn commit
them.
If you run into any questions about what I've tried to explain or encounter any odd errors, let me know. I did superficial testing of the script but it's quite possible I forgot some edge cases.
Good luck on getting your repositories restored!
精彩评论