Subversion Repositories DevTools

Rev

Rev 5287 | Details | Compare with Previous | Last modification | View Log | RSS feed

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