Apr 26th, 2018 under Programming PowerShell
Quick and easy backup for VisualSVN. Wraps the svnadmin.exe and performs a hotcopy of all repositories in the $source_path
, dumping them to the $backup_path
param
(
[string]$backup_path = $(throw "backup_path is required"),
[string]$source_path = $(throw "source_path is required"),
[string]$svnadmin = "C:\Program Files (x86)\VisualSVN Server\bin\svnadmin.exe"
)
# Validate paths exist
if (!(Test-Path $backup_path -PathType Container))
{
Write-Host "-backup_path $backup_path does not exist"
exit -1
}
if (!(Test-Path $source_path -PathType Container))
{
Write-Host "-source_path $source_path does not exist"
exit -1
}
if (!(Test-Path $svnadmin -PathType Leaf))
{
Write-Host "-svnadmin $svnadmin does not exist"
exit -1
}
# Root user/non-repository data
$files = Get-ChildItem $source_path | Where {!$_.PsIsContainer} | Select-Object Name
foreach ($file in $files)
{
Copy-Item (Join-Path $source_path $file.Name) (Join-Path $backup_path $file.Name)
}
# List of repository names (sub-directories under source path
$repositories = Dir $source_path | Where {$_.mode -match "d"} | Select name
ForEach ($repo in $repositories)
{
Write-Host $repo.Name
# Remove existing backup directory for the repository
if (Test-Path (Join-Path $backup_path $repo.Name))
{
Remove-Item -path (Join-Path $backup_path $repo.Name) -recurse -force
}
# Perform hot copy
& $svnadmin "hotcopy" (Join-Path $source_path $repo.Name) (Join-Path $backup_path $repo.Name)
}