# ============================================================================================== # # Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 2009 # # NAME: vmsync # # AUTHOR: Keith Luken # DATE : 1/21/2014 # # COMMENT: This script will read a file continaing the names of RC Grousp to start syncing. It will check if any volumes are # # ============================================================================================== # * Software Dependencies: * # - Microsoft PowerShell * # - VMWare PowerCLI * # - 3par cli # # This script sill take a parameter to filter voluem names and identify all RC groups that match that # filter and then begin replication on each of them. # # # ==============================================================================================# # EXIT CODES: # 1 - One of more volumes are syncing # 10 - Input file error or missing # 100 - Some type of failure processing one or more RC Groups # # ==============================================================================================# param ( [string]$arrayname = "arrayname", # the arrayname used to call for hardware snapshots (do NOT use FQDN) [string]$rclistfile = "testlist.txt", # Volume names to identify [string]$repretry = "1", # if RC is syncing retry this many times [string]$retryinterval = "30", # Time to wait beofre retrying [string]$logging = "yes" # if not no then output files will be generated for each grouping of actions ) # ============================================================================================== # Variables # ============================================================================================== $exitcode = 0 $passwordfile = $arrayname + "_admin.pwfile" # used for the 3par password file $rcgroups = @() # Will contain the list of all RC Groups processed $rcsyncing = @() # Will contain any RC groups that were syncing when attempted $rcfails = @() # Will contain any RC Groups that failed # ============================================================================================== # Functions # ============================================================================================== Function InitArray # This function will set up your environement variable for the hardware snaps { $env:TPDSYSNAME = $arrayname $env:TPDPWFILE = $passwordfile } Function GetRCGroups { Write-Host `nGetting contents of file $rclistfile `n if (Test-Path $rclistfile){ $rclist = Get-Content $rclistfile }else{ Write-Host "INPUT FILE DOES NOT EXIST!" Exit 10 } if ($rclist.count -eq 0){ Write-Host "INPUT FILE EMPTY!" Exit 10 } foreach ($rcg in $rclist){ Write-Host `n"Procssing RC group: "$rcg $rcg = $rcg.trim() if ($rcg -ne ""){ EnumerateRC $rcg } } } Function EnumerateRC { PARAM ($rcgroup) $synclist =@() Write-Host Enumerating RC group: $rcgroup $rcfile = $rcgroup + "_" + $unum + ".txt" $cline = "showrcopy groups " + $rcgroup + " >" + $rcfile + " && exit 0 || exit 1" #Write-Host `nRunning command line: $cline &cmd.exe /c $cline if ($LastExitCode -gt 0) { Write-Host Listing RC group failed. $LastExitCode $script:rcfails += $rcgroup $script:exitcode = 100 if (Test-Path $rcfile) {Remove-Item $rcfile} return } $rcdata = Get-Content $rcfile if (Test-Path $rcfile) {Remove-Item $rcfile} #Write-Host `nProcessing $rcdata.count lines from file $rcfile $readline = $false foreach ($line in $rcdata) { $line = $line.trim() if (!($line -eq "")){ $t = $line.Split(" ") if ($readline){ Write-Host Checking volume: $t[0] if ($line -like "*syncing*") { $synclist += $t[0] Write-Host Following volume is still syncing: $t[0] } } if ($t[0] -contains "LocalVV") {$readline = $true} } } if ($synclist -gt 0) { Write-Host `nOne or more volumes is currently syncing... $script:rcsyncing += $rcgroup }else{ StartRC $rcgroup } } Function StartRC { PARAM ($startgroup) Write-Host `nStarting replication for RC group $startgroup $cline = "syncrcopy " + $startgroup +" >" + $rcfile + " && exit 0 || exit 1" Write-Host `nRunning command line: $cline & cmd.exe /c $cline if ($LastExitCode -gt 0) { Write-Host Starting RC group $startgroup failed! Returned: $LastExitCode $script:exitcode = 90 } $rcdata = Get-Content $rcfile if (Test-Path $rcfile) {Remove-Item $rcfile} if ($rcdata -like "*Error*"){ $script:exitcode = 90 Write-Host --Sync command failed and returned:`n`t $rcdata } } Function RCRetry { if ($script:rcsyncing.count -eq 0){return} while ($script:repretry -gt 0){ Write-Host `n`nProcessing RC Groups to retry Write-Host `nPausing $script:retryinterval seconds Start-Sleep -s $script:retryinterval $t = $script:rcsyncing $script:rcsyncing = @() foreach ($r in $t){ Write-Host Retrying RC group $r EnumerateRC $r } $script:repretry = ($script:repretry - 1) Write-Host `nNumber of retries remaining: $script:repretry } } Function WrapUp { if ($script:rcsyncing -gt 0) { Write-Host `n`nThe following RC Groups were unable to start becsaue they were already repliciating:`n $c = 0 foreach ($i in $script:rcsyncing){ Write-Host $script:rcsyncing[$c] $c++ } } if ($script:rcfails -gt 0) { Write-Host `n`nThe following RC Groups encountered an error:`n $c = 0 foreach ($i in $script:rcfails){ Write-Host $script:rcfails[$c] $c++ } } } Function GenerateUNUM { $script:unum = Get-Date -format MMdd_HHmmssff } # ==============================================================================================# # Main Processing # ==============================================================================================# Clear-Host Write-Host Write-Host Using array name:`t $arrayname Write-Host Using contents of file: $rclistfile Write-host Retry attempts: `t`t $repretry Write-host Retry interval in seconds: `t $retryinterval GenerateUNUM InitArray GetRCGroups RCRetry WrapUp Write-Host `n`nEnding and returing exit code: $exitcode `n`n Exit $exitcode Write-Host End of script.`n