Tuesday, 14 October 2014

Vol-CreatorX4.ps1

Continuing the X4 series: SVM-CreatorX4.ps1 and Schedule-CreatorX4.ps1

The final part of building the 4 Cluster & 4 SVM lab, is creating volumes, protecting those volumes, and setting CIFS shares.

#######################
## VOL-CreatorX4.ps1 ##
#######################

## INTRODUCTION ##
"";"<<<<< VOL-CreatorX4.ps1 >>>>>"
"This script creates a volume on -";""
"                  Site A, Cluster 1, SVM1 - and is protected with 3 copies (4 copies of the data):"
"---SnapMirror---> Site B, Cluster 1, SVM1"
"---SnapVault--->  Site A, Cluster 2, SVM1 ---SnapMirror---> Site B, Cluster 2, SVM1";""
"And additionally a qtree with a CIFS share.";""

## USER INPUTS ##
$Username     = Read-Host ">>> Enter Admin User "
$Password     = Read-Host ">>> Enter Password " -AsSecureString
$Credential   = New-Object System.Management.Automation.PsCredential($username,$password)
$VolumeName   = Read-Host ">>> Volume name "
$JunctionPath = "/" + $VolumeName
$CifsShare    = $VolumeName

## CLUSTER / SVM / VOL / CIFS SHARE INFO ##
$123 = 1,2,3; $0123 = 0,1,2,3
$Clusters = "NCA1","NCA2","NCB1","NCB2"
$Svms = "NCA1V1","NCA2V1","NCB1V1","NCB2V1"

"";">>> STEP 1: CREATE RW VOLUME ON PRODUCTION SVM";""
Connect-NcController $Clusters[0] -Credential $Credential
New-NcVol -Name $VolumeName -Aggregate aggr1 -JunctionPath $JunctionPath -SpaceReserve none -Type rw -VserverContext $Svms[0] -Size 2g

"";">>> STEP 2: CREATE DP VOLUME ON OTHER SVMs";""
$123 | foreach {
Connect-NcController $Clusters[$_] -Credential $Credential
New-NcVol -Name $VolumeName -Aggregate aggr1 -JunctionPath $null -SpaceReserve none -Type dp -VserverContext $Svms[$_] -Size 1g
}

# SNAPMIRRORS and SNAPVAULTS
$Attributes = Get-NcSnapmirror -Template
$Attributes.Status = ""

"";">>> STEP 3: CREATE (Site A, Cluster 1, SVM1) ---SnapMirror---> (Site B, Cluster 1, SVM1)";""
# $Clusters[2] is NCB1 / $Svms[2] is NCB1V1
Connect-NcController $Clusters[2] -Credential $Credential
New-NcSnapmirror -DestinationVserver $Svms[2] -DestinationVolume $VolumeName -SourceVserver $Svms[0] -SourceVolume $VolumeName -Schedule sm20min -Type dp
Invoke-NcSnapmirrorInitialize -DestinationVserver $Svms[2] -DestinationVolume $VolumeName

# Wait for SnapMirror to Initialize
$idle = $false
while(!$idle){
$idleState = (Get-NcSnapMirror -Attributes $Attributes -DestinationVserver $Svms[2] -DestinationVolume $VolumeName).Status
If($idleState -eq "idle"){ $idle = $true }
Else { "SnapMirror has not finished initializing. Sleeping for 10 seconds"; Sleep 10 }
}

"";">>> STEP 4: CREATE (Site A, Cluster 1, SVM1) ---SnapVault---> (Site A, Cluster 2, SVM1)";""
# $Clusters[1] is NCA2 / $Svms[1] is NCA2V1
Connect-NcController $Clusters[1] -Credential $Credential
New-NcSnapmirror -DestinationVserver $Svms[1] -DestinationVolume $VolumeName -SourceVserver $Svms[0] -SourceVolume $VolumeName -Schedule sv60min -Type vault -Policy 92x60min_16x24hrs
Invoke-NcSnapmirrorInitialize -DestinationVserver $Svms[1] -DestinationVolume $VolumeName

# Wait for SnapMirror to Initialize
$idle = $false
while(!$idle){
$idleState = (Get-NcSnapMirror -Attributes $Attributes -DestinationVserver $Svms[1] -DestinationVolume $VolumeName).Status
If($idleState -eq "idle"){ $idle = $true }
Else { "SnapMirror has not finished initializing. Sleeping for 10 seconds"; Sleep 10 }
}

"";">>> STEP 5: CREATE (Site A, Cluster 2, SVM1) ---SnapMirror---> (Site B, Cluster 2, SVM1)";""
# $Clusters[3] is NCB2 / $Svms[3] is NCB2V1
Connect-NcController $Clusters[3] -Credential $Credential
New-NcSnapmirror -DestinationVserver $Svms[3] -DestinationVolume $VolumeName -SourceVserver $Svms[1] -SourceVolume $VolumeName -Schedule sm60min -Type dp
Invoke-NcSnapmirrorInitialize -DestinationVserver $Svms[3] -DestinationVolume $VolumeName

# Wait for SnapMirror to Initialize
$idle = $false
while(!$idle){
$idleState = (Get-NcSnapMirror -Attributes $Attributes -DestinationVserver $Svms[3] -DestinationVolume $VolumeName).Status
If($idleState -eq "idle"){ $idle = $true }
Else { "SnapMirror has not finished initializing. Sleeping for 10 seconds"; Sleep 10 }
}

"";">>> STEP 6: MOUNT THE DP VOLUMES";""
$123 | foreach {
Connect-NcController $Clusters[$_] -Credential $Credential
Mount-NcVol -Name $VolumeName -JunctionPath $JunctionPath -VserverContext $Svms[$_]
}

"";">>> STEP 7: CREATE THE SHARES";""
$0123 | foreach {
Connect-NcController $Clusters[$_] -Credential $Credential
Add-NcCifsShare -Name $CifsShare -Path $JunctionPath -VserverContext $Svms[$_]
}

"";">>> THE END <<<";""

No comments:

Post a Comment