Subversion Repositories DevTools

Rev

Go to most recent revision | Details | 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
13
        Determine those that are mastered onthe master (ignore non Master Repos)
14
        Determine those Repos not on the current machine
15
        Setup as Slave Replicas those Repos that are not on the master
16
            Add this machine to the Masters list of replicators
17
            Create the Repo and link it to the Master
18
            Copy in Repo-wide hook files
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
 
50
 
51
#
52
#   Verify that the Master exists
53
#   
54
$masterSession = New-CimSession $MASTER -ErrorAction Ignore
55
If($masterSession -eq $null)
56
{
57
    Write-Error "The named computer ($MASTER) does not exist" -Category InvalidArgument
58
    Exit    
59
}
60
 
61
#
62
#   Get a list of all Repos Mastered on the Master
63
#
64
Get-SvnRepository -CimSession  $masterSession | Where { $_.Type -eq 'VdfsMaster' } | ForEach-Object {
65
    #
66
    #   See if the Repo exists locally
67
    #
68
    $repoName = $_.Name
69
    $repoData = Get-SvnRepository $repoName -ErrorAction SilentlyContinue
70
    if ($repoData -ne $null)
71
    {
72
        Write-Host ("{0,20} : {1}" -f $repoName, 'Already Exists')
73
        Return
74
    }
75
 
76
    #
77
    # Get a list of Replication Slaves for the Repo
78
    #
79
    $repoRepData = Get-SvnRepositoryReplication $repoName -CimSession $masterSession
80
    $replicators = $repoRepData.Replicators + "$env:COMPUTERNAME$"
81
    Set-SvnRepositoryReplication $repoName -Replicators $replicators -CimSession  $masterSession
82
 
83
    #
84
    #   Create the Repo
85
    #   Connect it to the Master
86
    #
87
    Write-Host ("{0,20} : {1}" -f $repoName, 'Creating Replica')
88
    $newRepo = New-SvnRepository $_.Name -Type VdfsSlave -MasterServer $MASTER
89
 
90
    #
91
    # Get Data about the new Repo
92
    # Need the Repo disk address
93
    #
94
    $repoInfo = GetRepoInfo $repoName
95
    If ($repoInfo -eq $null )
96
    {
97
        Write-Error 'Cannot fetch Repo Info for created Repo: $repoName'
98
        Return
99
    }
100
    $HookDst = $repoInfo.Path
101
    $HookSrc = Split-Path -parent $HookDst
102
    #Write-Host "HookDst: $HookDst"
103
    #Write-Host "HookSrc: $HookSrc"
104
    $HookFileCount = 0
105
    Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {
106
        $srcFile = $_.Name
107
        Write-Host ("{0,20} : {1}" -f $repoName, "Copy Hook: $srcFile")
108
        Copy-Item $_.FullName -Destination ($HookDst + '/hooks') 
109
        $HookFileCount++
110
    }
111
    If ($HookFileCount -eq 0 )
112
    {
113
        Write-Host ("{0,20} : {1}" -f $repoName, "Warning: No Hook files found in the current Repository Store")
114
    }
115
}
116
 
117
 
118