| 5286 |
dpurdie |
1 |
<#
|
|
|
2 |
.SYNOPSIS
|
|
|
3 |
This Powershell script will promote a slave repo to a master
|
|
|
4 |
|
|
|
5 |
.DESCRIPTION
|
|
|
6 |
This Powershell script will promote a slave repo to a master
|
|
|
7 |
This is to be used as a part of a disaster recovery process
|
|
|
8 |
|
|
|
9 |
Assumtion: The Master is dead
|
|
|
10 |
|
|
|
11 |
It will
|
|
|
12 |
Disable replication on all servers
|
|
|
13 |
Promote a slave to a master
|
|
|
14 |
Reconfigure all slaves to be aware of the new master
|
|
|
15 |
Enable replication
|
|
|
16 |
|
|
|
17 |
.PARAMETER Repo
|
|
|
18 |
Name of the Repo to promote
|
|
|
19 |
|
|
|
20 |
.PARAMETER NewMaster
|
|
|
21 |
Name of new the new master server
|
|
|
22 |
|
|
|
23 |
.PARAMETER Servers
|
|
|
24 |
A list of server that are a part of the subverion network
|
|
|
25 |
These will be reconfigured to communicate with the new master
|
|
|
26 |
|
|
|
27 |
.EXAMPLE
|
|
|
28 |
PromoteSlave.ps1 -Repo MyRepo -NewMaster NewMaster -Servers Server1,Server2,Server3
|
|
|
29 |
|
|
|
30 |
.NOTES
|
|
|
31 |
Uses a number of cmdlets provided by VisualSVN.
|
|
|
32 |
|
|
|
33 |
#>
|
|
|
34 |
#
|
|
|
35 |
|
|
|
36 |
#
|
|
|
37 |
|
|
|
38 |
Param
|
|
|
39 |
(
|
|
|
40 |
[ parameter (Mandatory=$true,
|
|
|
41 |
HelpMessage="Enter the name of the new Master Server")]
|
|
|
42 |
[string] $Repo,
|
|
|
43 |
[ parameter (Mandatory=$true,
|
|
|
44 |
HelpMessage="Enter the name of the Repository to be remastered")]
|
|
|
45 |
[string] $NewMaster,
|
|
|
46 |
[ parameter (Mandatory=$true) ]
|
|
|
47 |
[string[]] $Servers
|
|
|
48 |
)
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
Function Promote-Slave( $REPO, $NEWMASTER, $SERVERS)
|
|
|
52 |
{
|
|
|
53 |
Write-Host 'REPO:' , $REPO
|
|
|
54 |
Write-Host 'NEWMASTER:' , $NEWMASTER
|
|
|
55 |
Write-Host 'SERVERS:' , $SERVERS
|
|
|
56 |
# Init Data
|
|
|
57 |
$ALLSERVERS = $SERVERS
|
|
|
58 |
$serversOk = $true
|
|
|
59 |
If ($ALLSERVERS -notcontains $NEWMASTER) { $ALLSERVERS += $NEWMASTER }
|
|
|
60 |
|
|
|
61 |
#
|
|
|
62 |
# Examine all the machines and ensure that they exist and that they are slaves
|
|
|
63 |
#
|
|
|
64 |
$ALLSERVERS | ForEach-Object {
|
|
|
65 |
Write-Host "Examine:", $_
|
|
|
66 |
$repoData = Get-SvnRepository -Name $REPO -CimSession $_ -ErrorAction SilentlyContinue
|
|
|
67 |
If ( ! $repoData )
|
|
|
68 |
{
|
|
|
69 |
Write-Error "Unknown server: $_" -Category InvalidArgument
|
|
|
70 |
$serversOk = $false
|
|
|
71 |
Break
|
|
|
72 |
}
|
|
|
73 |
$repoType = $repoData.Type
|
|
|
74 |
If ( $repoType -ne 'VdfsSlave' )
|
|
|
75 |
{
|
|
|
76 |
Write-Error "Repo on Server ($_) is not a Slave ($repoType)" -Category InvalidData
|
|
|
77 |
$serversOk = $false
|
|
|
78 |
Break
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
If (! $serversOk )
|
|
|
82 |
{
|
|
|
83 |
return
|
|
|
84 |
}
|
|
|
85 |
Write-Host "All servers Exist and are VdfsSlaves"
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
# Build up a list of replicators
|
|
|
89 |
# All the server names, remove the new master, append '$' so that its the machine name
|
|
|
90 |
#
|
|
|
91 |
$REPLICATORS = $ALLSERVERS | where { $_ -ne $NEWMASTER } | ForEach-Object { $_ + '$' }
|
|
|
92 |
|
|
|
93 |
#
|
|
|
94 |
# Display stuff
|
|
|
95 |
#
|
|
|
96 |
Write-Host "New Master:", $NEWMASTER
|
|
|
97 |
Write-Host "Replicators: ", $REPLICATORS
|
|
|
98 |
|
|
|
99 |
#
|
|
|
100 |
# Do the hard part
|
|
|
101 |
#
|
|
|
102 |
$ALLSERVERS | ForEach-Object {
|
|
|
103 |
Suspend-SvnRepository -name $REPO -CimSession $_
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
Switch-SvnRepository -Name $REPO -Role Master -Confirm:$false -CimSession $NEWMASTER
|
|
|
107 |
|
|
|
108 |
Set-SvnRepositoryReplication $REPO -Replicators $REPLICATORS -CimSession $NEWMASTER
|
|
|
109 |
Set-SvnRepositoryReplication $REPO -Enabled $true -CimSession $NEWMASTER
|
|
|
110 |
|
|
|
111 |
$ALLSERVERS | Where { $_ -ne $NEWMASTER } | ForEach-Object {
|
|
|
112 |
Set-SvnRepository $REPO -MasterServer $NEWMASTER -Confirm:$false -CimSession $_
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
$ALLSERVERS | ForEach-Object {
|
|
|
116 |
Resume-SvnRepository -name $REPO -CimSession $_
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
#
|
|
|
121 |
# Invoke the function
|
|
|
122 |
#
|
|
|
123 |
#Write-Host "Repo:", $REPO, "NewMaster:", $NEWMASTER, "Servers:", $SERVERS
|
|
|
124 |
Promote-Slave $REPO $NEWMASTER $SERVERS
|
|
|
125 |
|