Here is one option for you. It is a vbscript that dumps each
repository. You could easily alter this to do a hotcopy or incremental
dump if you wanted.

Basic usage is simple. Save this as a vbscript file into your
repository home folder (SVN default is c:\Repositories). Edit lines
21/22 and line 25 to match your needs (look for the ****).

I never could get this to run the command directly from the vbscript
so it generates a batch file on the file and executes that.

Watch out for line wraps from the html post. I've tried to fix
anything I saw here but it might change after I post it.


Joel Reinford




Option Explicit

'loop through folders and use svnadmin to dump all repos to a backup
location
'trying to run this type of command for each repo
'C:\Program Files\VisualSVN Server\bin>svnadmin dump C:\svnrepos
\MyProject > \\nas\folder\MyProject.bak

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Dim scriptPath, argCount, namedArgs
scriptPath = replace(wscript.scriptfullname, wscript.scriptname, "")
argCount= WScript.Arguments.Count
Set namedArgs = WScript.Arguments.Named

Dim fso, svnExePath, repoFolderPath, backupFolderPath

Set fso = CreateObject("Scripting.FileSystemObject")

'************* uncomment or edit for the correct path to svnadmin
****************
svnExePath = "C:\Program Files\VisualSVN Server\bin\svnadmin.exe"
'svnExePath = "C:\Program Files (x86)\VisualSVN Server\bin
\svnadmin.exe"

'************* edit this line to match your backup destination
****************
backupFolderPath = "c:\SvnBackup"

'only needs editing if you don't put it into the repos folder
repoFolderPath = scriptPath


If namedArgs.Exists("help") Or namedArgs.Exists("?") Then
 Wscript.Echo "Usage: "
 Wscript.Echo "/svn:<svn> is optional to enter the svnadmin executable
full path & name."
 Wscript.Echo " - default is " & svnExePath
 Wscript.Echo
 Wscript.Echo "/repos:<repos> is optional to select the svn
repositories folder."
 Wscript.Echo " - default is " & repoFolderPath
 Wscript.Echo
 Wscript.Echo "/backup:<backup> is optional to select the svn backup
destination folder."
 Wscript.Echo " - default is " & backupFolder
 Wscript.Quit
End If

If namedArgs.Exists("svn") Then
  svnExePath = Trim(namedArgs.Item("svn"))
End If

If namedArgs.Exists("repos") Then
 repoFolderPath= Trim(namedArgs.Item("path"))
End If

If namedArgs.Exists("backup") Then
 backupFolderPath= Trim(namedArgs.Item("backup"))
End If


DumpSvnRepos svnExePath, repoFolderPath, backupFolderPath


'create and execute a batch file to dump all of the repos
'for some reason running the dump command directly will not work
Function DumpSvnRepos(svnExePath, rootFolderPath, backupFolderPath)
    Dim rootFolder, subFolders, folder, file
    Dim logFileName, text

    Set rootFolder = fso.GetFolder(rootFolderPath)
    Set subFolders = rootFolder.SubFolders

    logFileName = Replace(wscript.ScriptFullName, ".vbs", ".bat")

    Set file = fso.OpenTextFile (logFileName, ForAppending, True)

    For Each folder in subFolders
      Wscript.Echo folder.Name
      text = Chr(34) & svnExePath & Chr(34) & " dump " _
& Chr(34) & repoFolderPath & "\" & folder.Name & Chr(34)  _
          & " > "  & Chr(34) & backupFolderPath & "\" & folder.Name &
".bak" & Chr(34)
      file.WriteLine(text)

    Next

  file.Close

  Wscript.Echo "Batch file created: " & logFileName
  runCommand logFileName

End Function



Function runCommand(commandLine)

        Dim shell, errorCode
        Set shell = CreateObject("WScript.shell")

        shell.Run commandLine, ,True 'command, WindowType, WaitOnReturn

        errorCode = err.Number
        If errorCode > 0 Then
                wscript.echo "runCommand Error " & err.Number & ": " & VbCrLf _
& commandLine & VbCrLf & err.Description
                logText "runCommand Error " & err.Number & ": " & vbTab _
& commandLine & vbTab & err.Description
                Err.Clear
        Else
                logText "runCommand Success : " & vbTab & commandLine
        End If

        runCommand = errorCode


End Function

Sub LogText(text)
    Dim file, logFile

    logFile = Replace(wscript.ScriptFullName, ".vbs", ".txt")

    Set file = fso.OpenTextFile (logFile, ForAppending , True)

    ' Writes Text every time you run this VBScript
    file.WriteLine(text)
    file.Close

End Sub

Reply via email to