Synchronize-CifsX4.ps1

Continuing the X4 Series (x4 SVMs/x4 copies of the data)...

Introduction

After having synchronized all 4 SVMs so that they have all the data volumes the primary SVM has, the next thing to keep in-sync is CIFS shares. All CIFS shares created on the primary SVM (1), should be also be on the data protection SVMs (2,3,4).

Image: 4 SVMs for 4-Copy (X4) Data Protection
We don’t need to synchronize Qtrees and Folders since this is brought across by the SnapMirror/SnapVault relations, but we need to be aware that if the script fails to create a CIFS share, it could simply be a case of waiting for the next replication before the Qtree/Folder exists. Additionally we want to make sure the volumes are mounted (to keep things relatively simple here, our SVM namespace has all volumes mounting from root.)

A Few Notes on the Script

i) Like the previous script, this one will run non-interactively like:

PS C:\> .\Synchronize-CifsX4.ps1 -User admin -Pass 123456

ii) Notice the one-line simplicity of synchronizing shares and ACLs in STEP 5, like:

$SRCshare | Set-NcCifsShare -VserverContext $Vservers[$_]
$SRC_ACL | Set-NcCifsShareAcl -VserverContext $Vservers[$_]

The Script

############################
## Synchronize-CifsX4.ps1 ##
############################

Param($User,$Pass);""
"Synchronize-CifsX4.ps1"
"======================";""
"The script is designed to Synchronize the CIFS shares in a 4 copy data-protection environment:
1 --SM--> 2
1 --SV--> 3 --SM--> 4.
It gets the details of the volumes in SVM 1 with their junction paths, and the CIFS shares and ACLs.";""

## USER INPUTS ##
If(!$User){$User = Read-Host ">>> Enter Admin User "}
If(!$Pass){$Pass = Read-Host ">>> Enter Password " -AsSecureString}
else {$Pass = $Pass | ConvertTo-SecureString  -AsPlainText -Force}
$Cred = New-Object System.Management.Automation.PsCredential($User,$Pass)

## CLUSTER / SVM / VOL / CIFS SHARE INFO ##
$1234 = 1,2,3,4; $234 = 2,3,4
$Clusters = "","NCA1","NCB1","NCA2","NCB2"
$Vservers = "","NCA1V1","NCB1V1","NCA2V1","NCB2V1"
Import-Module DataONTAP

## STEP 1 ##
"";"STEP 1: GET A LIST OF VOLUMES ON SVM 1 AND THEIR JUNCTION PATHS"
Connect-NcController -Name $Clusters[1] -Credential $Cred
$Attrs = Get-NcVol -Template
Initialize-NcObjectProperty -object $Attrs -name VolumeIdAttributes
$Attrs.VolumeIdAttributes.JunctionPath = ""
$SourceVols = Get-NcVol -Attributes $Attrs -VserverContext $Vservers[1]

## STEP 2 ##
"";"STEP 2: GET A LIST OF SHARES ON SVM 1 WITH THEIR PROPERTIES AND ACLS"
$SRCshares = Get-NcCifsShare -VserverContext $Vservers[1]
$SRCsharesACLs = Get-NcCifsShareAcl -VserverContext $Vservers[1]

## STEP 3 ##
"";"STEP 3: CHECK/CORRECT DR VOLUMES JUNCTION PATH"
$234 | foreach {
Connect-NcController -Name $Clusters[$_] -Credential $Cred

Foreach ($SourceVol in $SourceVols){
$SourceVolName = $SourceVol.Name
$DestVol = Get-NcVol -Attributes $Attrs -VserverContext $Vservers[$_] -Name $SourceVol
$DestVolName = $DestVol.Name

If($DestVol.VolumeIdAttributes.JunctionPath -ne $SourceVol.VolumeIdAttributes.JunctionPath){
Write-Host "$DestVolName on " + $Vservers[$_] + " Junction Path irregularity!!!" -ForegroundColor Red

If ($SourceVol.JunctionPath -eq $null){
Write-Host "$SourceVolName on " + $Vservers[1] + " has no junction path. Dismounting volume!!!" -ForegroundColor Red
Dismount-NcVol -Name $DestVolName -VserverContext $Vservers[$_]
      
} elseif ($DestVol.JunctionPath -eq $null){
Write-Host "$DestVolName on " + $Vservers[$_] + " has no junction path. Mounting volume!!!" -ForegroundColor Red
Mount-NcVol -Name $DestVolName -JunctionPath $SourceVol.JunctionPath -VserverContext $Vservers[$_]
      
} else {
Write-Host "$DestVolName on " + $Vservers[$_] + " has incorrect junction path. Re-mounting volume!!!" -ForegroundColor Red
Dismount-NcVol -Name $DestVolName -VserverContext $Vservers[$_]
Mount-NcVol -Name $DestVolName -JunctionPath $SourceVol.JunctionPath -VserverContext $Vservers[$_]
}
}            
}
}

## STEP 5 ##
"";"STEP 5: CHECK/CORRECT CIFS SHARES AND ACLs"
$234 | foreach {
Connect-NcController -Name $Clusters[$_] -Credential $Cred
$Attrs = Get-NcCifsShare -Template
$Attrs.ShareName = ""

Foreach ($SRCshare in $SRCshares){
$SRCshare.NcController = $null
$SRCshare.Vserver = $null
$SRCshareName  = $SRCshare.ShareName
$CheckForShare = Get-NcCifsShare -Attributes $Attrs -Name $SRCshareName -VserverContext $Vservers[$_]
      
If (!$CheckForShare){
Write-Host "$SRCshareName does not exist on the SVM " + $Vservers[$_] + " - adding the share!" -ForegroundColor Red
$SRCshare | Add-NcCifsShare -Name $SRCshareName -VserverContext $Vservers[$_]
} else {
$SRCshare | Set-NcCifsShare -VserverContext $Vservers[$_]
}
}

Foreach       ($SRC_ACL in $SRCsharesACLs){
$SRC_ACL.NcController = $null
$SRC_ACL.Vserver = $null  
$SRC_ACL | Set-NcCifsShareAcl -VserverContext $Vservers[$_]
}     
}

## THE END ##

Comments