2010-03-04 31 views
1

我在Windows VM框上运行VisualSVN。虚拟机崩溃并损坏了映像。恢复较旧的映像(2007年)后,我们发现我们的数据备份无法正常运行。因此,我在我的笔记本电脑(客户端)上安装了一堆项目(〜20),我想将它们推回VisualSVN服务器,该服务器现在是空的。从客户端副本恢复VisualSVN服务器

我知道这可以通过手动添加项目文件来完成,但由于我不想包含每个文件(即编译的文件),所以这会花费时间。任何建议将不胜感激。

+0

@Kevin,你是否曾经能够在不手动提交特定文件的情况下恢复svn服务器? – lostriebo 2010-03-26 02:10:17

回答

1

不幸的是,我没有你,但一个方式完全自动化的解决方案,以找出它使用与命令行工具的列表命令哪些文件在存储库的版本:

svn.exe list -R 

该命令将递归列出当前目录中SVN版本化的所有文件。一旦你有了这个列表,你可以将它们复制到另一个目录并批量提交到一个新的存储库。

将该命令与一些Powershell魔法相结合可能会使得重建库的任务变得尽可能无痛。

更新:

我花了一些时间使用PowerShell玩,想通了,你怎么能做到这一点。例如,我将解释原始存储库目录为C:\ source_repos \,新存储库目录为C:\ dest_repos \。

  1. 打开命令提示符。这可以通过附件开始菜单文件夹或通过运行Vista/Win7中的搜索框中的“cmd”或WinXP中的运行...来完成。
  2. 从命令提示运行下面的命令:

    cd C:\source_repos\ 
    echo File > filelist.csv 
    svn.exe list -R >> filelist.csv 
    

    第二个命令与含有字“文件”的第一行创建filelist.csv。第三个命令运行svn list命令并重定向输出以附加到filelist.csv。此时filelist.csv在第一行应该有“File”,后面跟着在你的svn目录中版本化的每个文件。

  3. 采取下面的代码并将其粘贴到一个名为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 
    

    您将需要修改$src$dest变量每次运行。

  4. 打开Powershell的(它可以在附件中找到在Vista/Win7的或Powershell的在WinXP)。转到您保存上述脚本的目录并运行它。如果您收到提到的错误“脚本执行这个系统上禁用”,在PowerShell中运行

    Set-ExecutionPolicy RemoteSigned 
    

    让本地脚本没有签名即可运行。

这应该做到这一点。如果一切顺利,你应该可以将 C:\dest_repos\svn add的所有文件转移到新的存储库,并将它们转换为 svn commit

如果遇到什么,我试图解释,或者遇到任何奇怪的错误,有任何问题,让我知道。我对剧本进行了肤浅的测试,但很可能我忘记了一些边缘案例。

好运让您的存储库恢复!