<# .SYNOPSIS This Powershell script will promote a slave repo to a master .DESCRIPTION This Powershell script will promote a slave repo to a master This is to be used as a part of a disaster recovery process Assumtion: The Master is dead It will Disable replication on all servers Promote a slave to a master Reconfigure all slaves to be aware of the new master Enable replication .PARAMETER Repo Name of the Repo to promote .PARAMETER NewMaster Name of new the new master server .PARAMETER Servers A list of server that are a part of the subverion network These will be reconfigured to communicate with the new master .EXAMPLE PromoteSlave.ps1 -Repo MyRepo -NewMaster NewMaster -Servers Server1,Server2,Server3 .NOTES Uses 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 (Mandatory=$true) ] [string[]] $Servers ) Function Promote-Slave( $REPO, $NEWMASTER, $SERVERS) { Write-Host 'REPO:' , $REPO Write-Host 'NEWMASTER:' , $NEWMASTER Write-Host 'SERVERS:' , $SERVERS # Init Data $ALLSERVERS = $SERVERS $serversOk = $true If ($ALLSERVERS -notcontains $NEWMASTER) { $ALLSERVERS += $NEWMASTER } # # Examine all the machines and ensure that they exist and that they are slaves # $ALLSERVERS | ForEach-Object { Write-Host "Examine:", $_ $repoData = Get-SvnRepository -Name $REPO -CimSession $_ -ErrorAction SilentlyContinue If ( ! $repoData ) { Write-Error "Unknown server: $_" -Category InvalidArgument $serversOk = $false Break } $repoType = $repoData.Type If ( $repoType -ne 'VdfsSlave' ) { Write-Error "Repo on Server ($_) is not a Slave ($repoType)" -Category InvalidData $serversOk = $false Break } } If (! $serversOk ) { return } Write-Host "All servers Exist and are VdfsSlaves" # 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:", $NEWMASTER Write-Host "Replicators: ", $REPLICATORS # # Do the hard part # $ALLSERVERS | ForEach-Object { Suspend-SvnRepository -name $REPO -CimSession $_ } Switch-SvnRepository -Name $REPO -Role Master -Confirm:$false -CimSession $NEWMASTER Set-SvnRepositoryReplication $REPO -Replicators $REPLICATORS -CimSession $NEWMASTER Set-SvnRepositoryReplication $REPO -Enabled $true -CimSession $NEWMASTER $ALLSERVERS | Where { $_ -ne $NEWMASTER } | ForEach-Object { Set-SvnRepository $REPO -MasterServer $NEWMASTER -Confirm:$false -CimSession $_ } $ALLSERVERS | ForEach-Object { Resume-SvnRepository -name $REPO -CimSession $_ } } # # Invoke the function # #Write-Host "Repo:", $REPO, "NewMaster:", $NEWMASTER, "Servers:", $SERVERS Promote-Slave $REPO $NEWMASTER $SERVERS