| 7571 |
dpurdie |
1 |
<#
|
|
|
2 |
.SYNOPSIS
|
|
|
3 |
This Powershell script will replicate one 'Pulse Repo from a Master Server
|
|
|
4 |
|
|
|
5 |
.DESCRIPTION
|
|
|
6 |
This Powershell script will setup a slave Repo from a specified
|
|
|
7 |
Master.
|
|
|
8 |
|
|
|
9 |
Assumption: The slave Repos will be setup on the current machine
|
|
|
10 |
|
|
|
11 |
It will
|
|
|
12 |
Determine trhe repo is mastered on the master (ignore non Master Repos)
|
|
|
13 |
Determine those Repos not on the current machine
|
|
|
14 |
Setup as Slave Replicas those Repos that are not on the current machine
|
|
|
15 |
Add this machine to the Masters list of replicators
|
|
|
16 |
Create the Repo and link it to the Master
|
|
|
17 |
Copy in hook files from the master
|
|
|
18 |
|
|
|
19 |
.PARAMETER Master
|
|
|
20 |
Name of new the master server
|
|
|
21 |
|
|
|
22 |
.EXAMPLE
|
|
|
23 |
ReplicateRepos.ps1 -Master MasterMachine -Repo DPG_SWBase
|
|
|
24 |
|
|
|
25 |
.NOTES
|
|
|
26 |
Uses a number of cmdlets provided by VisualSVN.
|
|
|
27 |
|
|
|
28 |
#>
|
|
|
29 |
#
|
|
|
30 |
|
|
|
31 |
#
|
|
|
32 |
|
|
|
33 |
Param
|
|
|
34 |
(
|
|
|
35 |
[ parameter (Mandatory=$true,
|
|
|
36 |
HelpMessage="Enter the name of the Master Repository server")]
|
|
|
37 |
[string] $MASTER,
|
|
|
38 |
|
|
|
39 |
[parameter (Mandatory=$true, HelpMessage="Enter the name of the Master Repo")]
|
|
|
40 |
[string] $REPO
|
|
|
41 |
)
|
|
|
42 |
|
|
|
43 |
#
|
|
|
44 |
# Get Data about a named Repo on the local machine
|
|
|
45 |
#
|
|
|
46 |
function GetRepoInfo( $repoName )
|
|
|
47 |
{
|
|
|
48 |
$repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Where { $_.Name -eq $repoName }
|
|
|
49 |
Return $RepoData
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
#
|
|
|
53 |
# Get information on a named repo on the named Computer
|
|
|
54 |
function GetRemoteRepoInfo( $repoName, $ComputerName )
|
|
|
55 |
{
|
|
|
56 |
$repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository -ComputerName $ComputerName | Where { $_.Name -eq $repoName }
|
|
|
57 |
Return $RepoData
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
#
|
|
|
61 |
# Convert Absolute Path to UNC on a named computer
|
|
|
62 |
#
|
|
|
63 |
Function AbsToUnc( $ComputerName, $absPath )
|
|
|
64 |
{
|
|
|
65 |
return '\\' + $ComputerName + '\' + $absPath.Replace(":","$")
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
#
|
|
|
69 |
# Verify that the Master exists
|
|
|
70 |
#
|
|
|
71 |
$masterSession = New-CimSession $MASTER -ErrorAction Ignore
|
|
|
72 |
If($masterSession -eq $null)
|
|
|
73 |
{
|
|
|
74 |
Write-Error "The named computer ($MASTER) does not exist" -Category InvalidArgument
|
|
|
75 |
Exit
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
#
|
|
|
79 |
# Get a list of all Repos Mastered on the Master
|
|
|
80 |
#
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
#Get-SvnRepository -CimSession $masterSession | Where { $_.Type -eq 'VdfsMaster' } | ForEach-Object {
|
|
|
84 |
#
|
|
|
85 |
# See if the Repo exists locally
|
|
|
86 |
#
|
|
|
87 |
$repoName = "Pulse-" + $REPO
|
|
|
88 |
$repoData = Get-SvnRepository $repoName -ErrorAction SilentlyContinue
|
|
|
89 |
if ($repoData -ne $null)
|
|
|
90 |
{
|
|
|
91 |
Write-Host ("{0,20} : {1}" -f $repoName, 'Already Exists')
|
|
|
92 |
Return
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
#
|
|
|
96 |
#
|
|
|
97 |
# See if the Master REpo Exists
|
|
|
98 |
#
|
|
|
99 |
$masterRepoData = Get-SvnRepository $REPO -ErrorAction SilentlyContinue -CimSession $masterSession
|
|
|
100 |
if ( $masterRepoData -eq $null )
|
|
|
101 |
{
|
|
|
102 |
Write-Host ("{0,20} : {1}" -f $REPO , 'Does not exist')
|
|
|
103 |
Return
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
#
|
|
|
107 |
# Get a list of Replication Slaves for the Repo
|
|
|
108 |
#
|
|
|
109 |
$repoRepData = Get-SvnRepository -Type VdfsSlave $REPO -ErrorAction SilentlyContinue -CimSession $masterSession
|
|
|
110 |
$replicators = $repoRepData.Replicators + "$env:COMPUTERNAME$"
|
|
|
111 |
Set-SvnRepository $REPO -ReplicatorsAuthenticatedByActiveDirectory $replicators -CimSession $masterSession
|
|
|
112 |
|
|
|
113 |
#
|
|
|
114 |
# Create the Repo
|
|
|
115 |
# Connect it to the Master
|
|
|
116 |
#
|
|
|
117 |
Write-Host ("{0,20} : {1}" -f $repoName, 'Creating Replica')
|
|
|
118 |
$newRepo = New-SvnRepository $repoName -Type VdfsSlave -MasterServer $MASTER -MasterRepository $REPO
|
|
|
119 |
|
|
|
120 |
#
|
|
|
121 |
# Get Data about the new Repo
|
|
|
122 |
# Need the Repo disk address
|
|
|
123 |
#
|
|
|
124 |
$repoInfo = GetRepoInfo $repoName
|
|
|
125 |
If ($repoInfo -eq $null )
|
|
|
126 |
{
|
|
|
127 |
Write-Error 'Cannot fetch Repo Info for created Repo: $repoName'
|
|
|
128 |
Return
|
|
|
129 |
}
|
|
|
130 |
$HookDst = $repoInfo.Path
|
|
|
131 |
|
|
|
132 |
#
|
|
|
133 |
# Determine the source of the hooks
|
|
|
134 |
#
|
|
|
135 |
$masterRepo = GetRemoteRepoInfo $REPO $MASTER
|
|
|
136 |
$masterHookPathUnc = AbsToUnc $MASTER ($masterRepo.Path + '\hooks')
|
|
|
137 |
$specialHooks = Test-Path ($masterHookPathUnc + '\specialhooks')
|
|
|
138 |
Write-Host ("{0,20} : {1}" -f $REPO, "Master Hooks: $masterHookPathUnc")
|
|
|
139 |
#Write-Host ("{0,20} : {1}" -f $repoName, "Special Hooks: $specialHooks")
|
|
|
140 |
|
|
|
141 |
$HookSrc = $masterHookPathUnc
|
|
|
142 |
#Write-Host "HookDst: $HookDst"
|
|
|
143 |
#Write-Host "HookSrc: $HookSrc"
|
|
|
144 |
$HookFileCount = 0
|
|
|
145 |
Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
|
|
|
146 |
$srcFile = $_.Name
|
|
|
147 |
Write-Host ("{0,20} : {1}" -f $REPO, "Copy Hook: $srcFile")
|
|
|
148 |
Copy-Item $_.FullName -Destination ($HookDst + '/hooks')
|
|
|
149 |
$HookFileCount++
|
|
|
150 |
}
|
|
|
151 |
If ($HookFileCount -eq 0 )
|
|
|
152 |
{
|
|
|
153 |
Write-Host ("{0,20} : {1}" -f $REPO, "Warning: No Hook files found in the current Repository Store")
|
|
|
154 |
}
|
|
|
155 |
If ($specialHooks)
|
|
|
156 |
{
|
|
|
157 |
Write-Host ("{0,20} : {1}" -f $repoName, "Copy specialhooks")
|
|
|
158 |
Copy-Item ($HookSrc + '\specialhooks') -Destination ($HookDst + '/hooks')
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
|