Blame | Last modification | View Log | RSS feed
<#.SYNOPSISThis Powershell script will promote a slave repo to a master.DESCRIPTIONThis Powershell script will promote a slave repo to a masterThis is to be used as a part of a disaster recovery processAssumtion: The Master is deadIt willDisable replication on all serversPromote a slave to a masterReconfigure all slaves to be aware of the new masterEnable replication.PARAMETER RepoName of the Repo to promote.PARAMETER NewMasterName of new the new master server.PARAMETER ServersA list of server that are a part of the subverion networkThese will be reconfigured to communicate with the new master.EXAMPLEPromoteSlave.ps1 -Repo MyRepo -NewMaster NewMaster -Servers Server1,Server2,Server3.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 (Mandatory=$true) ][string[]] $Servers)Function Promote-Slave( $REPO, $NEWMASTER, $SERVERS){Write-Host 'REPO:' , $REPOWrite-Host 'NEWMASTER:' , $NEWMASTERWrite-Host 'SERVERS:' , $SERVERS# Init Data$ALLSERVERS = $SERVERS$serversOk = $trueIf ($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 SilentlyContinueIf ( ! $repoData ){Write-Error "Unknown server: $_" -Category InvalidArgument$serversOk = $falseBreak}$repoType = $repoData.TypeIf ( $repoType -ne 'VdfsSlave' ){Write-Error "Repo on Server ($_) is not a Slave ($repoType)" -Category InvalidData$serversOk = $falseBreak}}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:", $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 $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:", $SERVERSPromote-Slave $REPO $NEWMASTER $SERVERS