Rev 5288 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<#.SYNOPSISThis Powershell script will create a Master and Slave Repos.DESCRIPTIONThis Powershell script will create a Master and Slave ReposIt willCreate the Master on the current machineCopy Global Hooks into the new RepoCreate SlavesCopy Global Hooks into the new slaves.PARAMETER RepoName of the Repo to create.PARAMETER SlavesA list of Slave servers that are a part of the subversion networkThese will be reconfigured to communicate with the new masterIf none are provided then only the Master Repo will be created.EXAMPLECreateRepo.ps1 -Slave auawssvn001,cloudasvn03.NOTESUses a number of cmdlets provided by VisualSVN.#>#Param([ parameter (Mandatory=$true,HelpMessage="Enter the name of the new Repository")][string] $Repo,[ parameter () ][string[]] $Slaves)## Get information on the current SVN server#function GetSvnInfo(){$repoData = Get-CimInstance -Namespace "root\VisualSVN" -ClassName VisualSVN_ServiceReturn $RepoData}## Get information on a named repofunction 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(":","$")}## Determine the root of the Repositores$SvnInfo = GetSvnInfoif ($SvnInfo -eq $null){Write-Error 'Cannot get VisualSVN info'Exit}# Validate the Repo Root$repoRoot = $SvnInfo.RepositoriesRootIf (!(Test-Path $repoRoot)){Write-Error 'RepositoriesRoot - Does not exist'Exit}## Ensure the named repo does not exist#$RepoData = Get-SvnRepository -Name $Repo -ErrorAction SilentlyContinueIf ( $RepoData ){Write-Host "Repository ($Repo) already exists"Return}## Create the Master Repo#Write-Host 'Creating Master Repository'$RepoData = New-SvnRepository -Name $Repo -Type VdfsMaster## Copy in global hooks#Write-Host 'Transfer Global Hooks'$RepoInfo = GetRepoInfo $Repo$HookSrc = $repoRoot$hookPath = $RepoInfo.Path + '/hooks'$HookFileCount = 0Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {$srcFile = $_.NameCopy-Item $_.FullName -Destination $hookPath$HookFileCount++}Write-Host "Hook Files Copied: $HookFileCount"## Create Slaves too#If ( $Slaves ){#Write-Host $Slaves## Add Slave list to the Master#$Replicators = $Slaves | ForEach-Object { $_ + '$' }Set-SvnRepositoryReplication $Repo -Replicators $Replicators -Enabled:$true$Slaves | ForEach-Object {Write-Host "Creating Slave Repository $_"$NewRepo = New-SvnRepository $Repo -MasterServer $env:COMPUTERNAME -Type VdfsSlave -CimSession $_## Copy Hooks to the Slave## Get target Repo Information# Want the path to the hooks directory#$targetRepo = GetRemoteRepoInfo $Repo $_$hookPath = $targetRepo.Path + '\hooks'$hookPathUnc = AbsToUnc $_ $hookPath## Copy files to Remote Computer##Write-Host "Hooks Found", $hookPathUnc$HookFileCount = 0Get-ChildItem $HookSrc -Filter '*.cmd' | ForEach-Object {$srcFile = $_.NameCopy-Item $_.FullName -Destination $hookPathUnc$HookFileCount++}Write-Host "Hook Files Copied: $HookFileCount"}}