Blame | Last modification | View Log | RSS feed
<#.SYNOPSISThis Powershell script will replicate one 'Pulse Repo from a Master Server.DESCRIPTIONThis Powershell script will setup a slave Repo from a specifiedMaster.Assumption: The slave Repos will be setup on the current machineIt willDetermine trhe repo is mastered on the master (ignore non Master Repos)Determine those Repos not on the current machineSetup as Slave Replicas those Repos that are not on the current machineAdd this machine to the Masters list of replicatorsCreate the Repo and link it to the MasterCopy in hook files from the master.PARAMETER MasterName of new the master server.EXAMPLEReplicateRepos.ps1 -Master MasterMachine -Repo DPG_SWBase.NOTESUses a number of cmdlets provided by VisualSVN.#>##Param([ parameter (Mandatory=$true,HelpMessage="Enter the name of the Master Repository server")][string] $MASTER,[parameter (Mandatory=$true, HelpMessage="Enter the name of the Master Repo")][string] $REPO)## Get Data about a named Repo on the local machine#function GetRepoInfo( $repoName ){$repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository | Where { $_.Name -eq $repoName }Return $RepoData}## Get information on a named repo on the named Computerfunction GetRemoteRepoInfo( $repoName, $ComputerName ){$repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_Repository -ComputerName $ComputerName | Where { $_.Name -eq $repoName }Return $RepoData}## Convert Absolute Path to UNC on a named computer#Function AbsToUnc( $ComputerName, $absPath ){return '\\' + $ComputerName + '\' + $absPath.Replace(":","$")}## Verify that the Master exists#$masterSession = New-CimSession $MASTER -ErrorAction IgnoreIf($masterSession -eq $null){Write-Error "The named computer ($MASTER) does not exist" -Category InvalidArgumentExit}## Get a list of all Repos Mastered on the Master##Get-SvnRepository -CimSession $masterSession | Where { $_.Type -eq 'VdfsMaster' } | ForEach-Object {## See if the Repo exists locally#$repoName = "Pulse-" + $REPO$repoData = Get-SvnRepository $repoName -ErrorAction SilentlyContinueif ($repoData -ne $null){Write-Host ("{0,20} : {1}" -f $repoName, 'Already Exists')Return}### See if the Master REpo Exists#$masterRepoData = Get-SvnRepository $REPO -ErrorAction SilentlyContinue -CimSession $masterSessionif ( $masterRepoData -eq $null ){Write-Host ("{0,20} : {1}" -f $REPO , 'Does not exist')Return}## Get a list of Replication Slaves for the Repo#$repoRepData = Get-SvnRepository -Type VdfsSlave $REPO -ErrorAction SilentlyContinue -CimSession $masterSession$replicators = $repoRepData.Replicators + "$env:COMPUTERNAME$"Set-SvnRepository $REPO -ReplicatorsAuthenticatedByActiveDirectory $replicators -CimSession $masterSession## Create the Repo# Connect it to the Master#Write-Host ("{0,20} : {1}" -f $repoName, 'Creating Replica')$newRepo = New-SvnRepository $repoName -Type VdfsSlave -MasterServer $MASTER -MasterRepository $REPO## Get Data about the new Repo# Need the Repo disk address#$repoInfo = GetRepoInfo $repoNameIf ($repoInfo -eq $null ){Write-Error 'Cannot fetch Repo Info for created Repo: $repoName'Return}$HookDst = $repoInfo.Path## Determine the source of the hooks#$masterRepo = GetRemoteRepoInfo $REPO $MASTER$masterHookPathUnc = AbsToUnc $MASTER ($masterRepo.Path + '\hooks')$specialHooks = Test-Path ($masterHookPathUnc + '\specialhooks')Write-Host ("{0,20} : {1}" -f $REPO, "Master Hooks: $masterHookPathUnc")#Write-Host ("{0,20} : {1}" -f $repoName, "Special Hooks: $specialHooks")$HookSrc = $masterHookPathUnc#Write-Host "HookDst: $HookDst"#Write-Host "HookSrc: $HookSrc"$HookFileCount = 0Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {$srcFile = $_.NameWrite-Host ("{0,20} : {1}" -f $REPO, "Copy Hook: $srcFile")Copy-Item $_.FullName -Destination ($HookDst + '/hooks')$HookFileCount++}If ($HookFileCount -eq 0 ){Write-Host ("{0,20} : {1}" -f $REPO, "Warning: No Hook files found in the current Repository Store")}If ($specialHooks){Write-Host ("{0,20} : {1}" -f $repoName, "Copy specialhooks")Copy-Item ($HookSrc + '\specialhooks') -Destination ($HookDst + '/hooks')}