Skip to content

Instantly share code, notes, and snippets.

@jonsagara
Created April 12, 2012 19:42
Show Gist options
  • Save jonsagara/2370485 to your computer and use it in GitHub Desktop.
Save jonsagara/2370485 to your computer and use it in GitHub Desktop.
PowerShell Hot Copy Backup of Subversion repositories
# -------------------------------------------------------------------------------------------------
# Does a hot copy backup of all Subversion repositories.
# -------------------------------------------------------------------------------------------------
$hotCopySource = "C:\Subversion\Repositories"
$hotCopyDest = "C:\SubversionBackups"
$svnadmin_exe = "C:\Program Files (x86)\VisualSVN Server\bin\svnadmin.exe"
$7za_exe = "C:\Subversion\7za.exe"
if ([IO.Directory]::Exists($hotCopyDest)) {
Write-Output "Remove Directory $hotCopyDest"
Remove-Item $hotCopyDest -Recurse -Force
}
else {
Write-Output "Directory $hotCopyDest does not exist. Skipping deletion"
}
Write-Output "Create Directory $hotCopyDest"
mkdir $hotCopyDest | Out-Null
$oldDir = pwd
cd $hotCopySource
Write-Output "Hot Copy $hotCopySource"
$repoDirs = dir | where { $_.PsIsContainer } | foreach-object { $_.Name }
foreach ($repoDir in $repoDirs) {
$srcDir = [IO.Path]::Combine($hotCopySource, $repoDir)
$destDir = [IO.Path]::Combine($hotCopyDest, $repoDir)
Write-Output "Hot Copy $srcDir"
& $svnadmin_exe hotcopy $srcDir $destDir
if ($lastExitCode -ne 0) {
throw "Error: failed to 'svnadmin hotcopy' $srcDir to $destDir"
}
}
$7zOutput = [IO.Path]::Combine($hotCopyDest, "Subversion Backups.7z")
& $7za_exe a $7zOutput $hotCopyDest\* -r
if ($LastExitCode -ne 0) {
throw "Error: failed to compress $hotCopyDest\* using 7-zip"
}
cd $oldDir
Write-Output "Done"
@vitormauiciovh
Copy link

The script woks very fine. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment