从客户端副本还原VisualSVN服务器

时间:2010-03-04 20:13:25

标签: svn visualsvn-server

我在Windows VM框上运行VisualSVN。 VM崩溃并损坏了映像。恢复旧图像(2007)后,我们发现我们的数据备份无法正常运行。因此我在我的笔记本电脑(客户端)上有一堆项目(~20),我想将它们推回到VisualSVN服务器,现在它已经空了。

我知道这可以通过简单地手动添加项目文件来完成,但这需要时间,因为我不想包含每个文件(即编译文件)。任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:1)

不幸的是,我没有一个完全自动化的解决方案,但是找出存储库中版本文件的一种方法是使用命令行工具 list 命令:

svn.exe list -R

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

将该命令与某些Powershell魔法相结合可能会使重建存储库的任务尽可能轻松。

<强>更新

我花了一些时间和Powershell一起玩,并想出如何做到这一点。对于示例,我将解释原始存储库目录是C:\ source_repos \,新存储库目录是C:\ dest_repos \。

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

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

    第二个命令创建filelist.csv,第一行包含单词“File”。第三个命令运行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. Open Powershell(可以在Vista / Win7上的附件或WinXP中的Powershell中找到)。转到保存上述脚本的目录并运行它。如果您收到错误提及“在此系统上禁用了脚本的执行”,请运行

    Set-ExecutionPolicy RemoteSigned
    
    PowerShell中的

    使本地脚本无需签名即可运行。

那应该这样做。如果一切顺利,您应该能够将C:\dest_repos\svn add所有文件转到新存储库并svn commit

如果您对我尝试解释或遇到任何奇怪错误的任何疑问,请告诉我。我对脚本进行了表面测试,但我很可能忘记了一些边缘情况。

祝你的存储库恢复好运!

相关问题