Blame | Last modification | View Log | RSS feed
<#.SYNOPSISThis Powershell script will change the Mastership of a SVN Repo.DESCRIPTIONThis Powershell script will chnage the Mastership of a SVN RepoAssumtion: The Repo is present on the current machineIt willDetermine the location of the Master RepoAsk the Master for the list of Slave Repo serversCheck that the new master is not the current masterCheck that the new master is one of the slave serversReconfigure the Repos on all servers.PARAMETER RepoName of the Repo to re-master.PARAMETER NewMasterName of new the new master server.PARAMETER ComputerNameName of computer to examne for repoDefault is the current computer.EXAMPLEChangeMaster.ps1 -Repo MyRepo -NewMaster NewMaster.NOTESUses a number of cmdlets provided by VisualSVN.#>##Param([ parameter (Mandatory=$true,HelpMessage="Enter the name of the new Master Server")][string] $Repo,[ parameter (Mandatory=$true,HelpMessage="Enter the name of the Repository to be remastered")][string] $NEWMASTER,[ parameter () ][string] $ComputerName)Function Remaster-Repo( $REPO, $NEWMASTER){# Init Data$ALLSERVERS = @()## Examine current machine and determine data about the repo#$argList = @{Namespace= 'root\VisualSVN' ; ClassName = 'VisualSVN_Repository'; ErrorVariable = 'gciError'}If ($ComputerName){$testSession = New-CimSession $ComputerName -ErrorAction IgnoreIf($testSession -eq $null){Write-Error "The named computer ($ComputerName) does not exist" -Category InvalidArgumentReturn}Remove-CimSession $testSession$argList.Add('ComputerName', $ComputerName )}#Write-Host 'argList:' , ($argList | Format-List | Out-String)$repoData = Get-CimInstance @argList | where { $_.Name -eq $REPO }If ($repoData -eq $null ){Write-Error "The repo ($REPO) does not exist on the local machine" -Category InvalidArgumentReturn}#Write-Host 'RepoData:' , ($repoData | Format-List | Out-String)$CURMASTER = $repoData.MasterServerIf (! $CURMASTER) { $CURMASTER = $env:COMPUTERNAME }Write-Host "Current Master:", $CURMASTER$CURMASTER = $CURMASTER.ToUpper()$NEWMASTER = $NEWMASTER.ToUpper()$ALLSERVERS += $CURMASTERIf ( $NEWMASTER -eq $CURMASTER ){# This is not an errorWrite-Host "New Master is the same as the Current Master"Return}## Examine the repo on the Master#$RepoData = Get-SvnRepositoryReplication $REPO -CimSession $CURMASTER#Write-Host ($RepoData | Format-List | Out-String)$RepoData.Replicators | ForEach-Object {$name = $_ -match '\w+\\(\w+)'If ( $name ){$ALLSERVERS += $matches[1].ToUpper()}else{Write-Error "Replicator data in unexepcted form: $_" -Category InvalidDataReturn;}}Write-Host "All Servers:", $ALLSERVERS## Test that new master is in the set of known servers#If ($ALLSERVERS -contains $NEWMASTER ){# Build up a list of replicators# All the server names, remove the new master, append '$' so that its the machine name#$REPLICATORS = $ALLSERVERS | where { $_ -ne $NEWMASTER } | ForEach-Object { $_ + '$' }## Display stuff#Write-Host "New Master:", $NEWMASTERWrite-Host "Replicators: ", $REPLICATORS## Do the hard part#$ALLSERVERS | ForEach-Object { Suspend-SvnRepository -name $REPO -CimSession $_ }Switch-SvnRepository -Name $REPO -Role Master -Confirm:$false -CimSession $NEWMASTERSet-SvnRepositoryReplication $REPO -Replicators $REPLICATORS -CimSession $NEWMASTERSet-SvnRepositoryReplication $REPO -Enabled $true -CimSession $NEWMASTERSwitch-SvnRepository -name $REPO -Role Slave -MasterServer $NEWMASTER -Confirm:$false -CimSession $CURMASTER$ALLSERVERS | Where { $_ -ne $NEWMASTER } | ForEach-Object {Set-SvnRepository $REPO -MasterServer $NEWMASTER -Confirm:$false -CimSession $_}$ALLSERVERS | ForEach-Object { Resume-SvnRepository -name $REPO -CimSession $_ }}else{Write-Error "The new master ($NEWMASTER) is not one of the replicated slaves : $ALLSERVERS" -Category InvalidArgumentReturn}}## Invoke the function##Write-Host "Repo:", $REPO, "NewMaster:", $NEWMASTERRemaster-Repo $REPO $NEWMASTER