Created
April 12, 2012 19:42
-
-
Save jonsagara/2370485 to your computer and use it in GitHub Desktop.
PowerShell Hot Copy Backup of Subversion repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------------------------------- | |
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script woks very fine. Thanks!