Microsoft Virtualization Discussions

Need help with PS toolkit for query to remove clones and create new ones for 17 NFS volumes..

JasonKennedy
5,809 Views

Hi everyone,

 

I've not that new with PowerShell and have been using it for some time but am by no means a Guru.

 

I have 17 NFS volumes, each containing a VMDK, which is attached to a SQL server. I'm trying to simplify my refresh process to out SQL DEV server. I have been using VMware PowerCLI and NetApp CLI to obtain my results but it's time-consuming..

I’d like to build a script that would:

  • Query for the Volumes
    • Get-NcVol -Volume ESX_NFS_N*
  • Query for the clones
  • Dismount and delete the clones
  • Query for the latest snapshot
  • Create a clone from the latest Snapshot
  • Mount junction path

 

I found a script close to what I was looking for @ https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/Getting-the-latest-snapshot-name/td-p/135117

 

# get all snapmirror destination volumes for the desired SVM
Get-NcSnapmirror -Query @{ DestinationVserver = $svmName; RelationshipType = "data_protection"; } | ForEach-Object { 
    # cleanup the old clone
    $currentClone = Get-NcVolClone -Query @{ Vserver = $svmName; ParentVolume = $_.DestinationVolume } | Get-NcVol
    $currentClone | Dismount-NcVol -Confirm:$false | Set-NcVol -Offline -Confirm:$false | Remove-NcVol -Confirm:$false
    
    # get the newest snapshot on the snapmirorr destination volume
    $newestSnap = Get-NcVol -Vserver $svmName -Name $_.DestinationVolume | Get-NcSnapshot | Sort-Object -Property Created -Descending | Select-Object -First 1
# create the volume clone
    $splat = @{
        # the SVM to use for the clone...the same as the source volume
        'Vserver' = $svmName;
        
        # the name of the new volume
        'CloneVolume' = "$($_.DestinationVolume)_clone";
# the parent SVM
        'ParentVserver' = $svmName;
# the source volume
        'ParentVolume' = $_.DestinationVolume;
# the source snapshot
        'ParentSnapshot' = $newestSnap.Name
# thin provision
        'SpaceReserve' = "none";
# junction at the new volume name, not needed if using LUNs
        'JunctionPath' = "/$($_.DestinationVolume)_clone"
# make sure it's an active junction, not needed if using LUNs
        'JunctionActive' = $true;
}
    
    New-NcVolClone @splat

# not included, making a LUN in the volume available
}

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

JasonKennedy
5,745 Views

and by the way, that command is

 

Connect-NcController "Controller" -Vserver "vservername"

View solution in original post

9 REPLIES 9

donny_lang
5,796 Views

Based on the example code, I'd say that it would handle most of what you're looking for with some customization for your environment (and filtering to only collect the specific volumes that you're looking for, of course). 

 

Do you have any specific questions regarding that code or your use case that I can help out with? 

JasonKennedy
5,788 Views

Hi Donny!

 

Well, The current script builds an array using Get-NcSanpmirror, which also builds the variables that are needed for each process after that. I am having issues build my array and then executing a process for each item in the array..

 

For testing purposes, I have 4 flexvols; test, test1, test2, test3. These flexvols have 3 snaps each with the latest snap being used to clone the volume. I can see where the example script finds the volumes based on type (DP), and then build the array from there.. I can build an array but can figure out how to process each line of the array (ForEach-Object)..

 

This is what I have been working on:

Get-NcVolClone -Query @{ Vserver = $svmname;ParentVolume = "Test*"}

PS C:\WINDOWS\system32> Get-NcVolClone -Query @{ Vserver = $svmname;ParentVolume = "Test*"}


Name                      ParentVolume              ParentSnapshot            Aggregate                 Vserver                                                                                             
----                      ------------              --------------            ---------                 -------                                                                                             
Test_clone                Test                      clone_Test_clone_06012.0  aggr1_N4                  EPIC-DC2-NFS01                                                                                      
Test1_clone               Test1                     clone_Test1_clone.0       aggr2_N3                  EPIC-DC2-NFS01                                                                                      
Test2_clone               Test2                     clone_Test2_clone.0       aggr1_N3                  EPIC-DC2-NFS01                                                                                      
Test3_clone               Test3                     clone_Test3_clone.0       aggr1_N4                  EPIC-DC2-NFS01                                              

Now I want to process each line to remove the clone and create a new one using the latest snapshot.

 

I'm not that good at PS and struggle with arrays..

 

Thanks for helping...

JasonKennedy
5,787 Views

I meant to include what i have don't so far..

The below sctipt does work to build the array, find the clones and then remove them, but I had to specify the variables. This means creating the new cloned volumes won't work because you can't use a Wildcard to specify a name..

$svmname = "EPIC-DC2-NFS01"
Get-NcVolClone -Query @{ Vserver = $svmname; ParentVolume = "Test*"} |ForEach-Object {
$currentClone = Get-NcVolClone -Query @{ Vserver = $svmname; ParentVolume = "Test*"} | Get-NcVol
$currentClone | Dismount-NcVol -Confirm:$false | Set-NcVol -Offline -Confirm:$false | Remove-NcVol -Confirm:$false
}

donny_lang
5,782 Views

Thanks for the details! As to your question, I would just include the code that selects the latest snapshot and creates the new clone in the foreach loop (the example does this - the foreach loop begins towards the end of the 2nd line and doesn't close until line 33, encapsulating the entire script -  the code on line 8 is the part where the new snapshot is selected, and the parameters defined on lines 10-28 are used as inputs for the New-NcVol command on line 30). So your foreach loop will both delete the existing clone and then rebuild a new one for each volume in that original Get-NcVolClone output.

 

Donny

JasonKennedy
5,762 Views

Adding more work.. 

 

The code deleting the clones works as expected but not building the new clones. When i look at the variable $splat, it has what I believe to be everything to create a clone of the parent volume but errors out.. I'll add those errors as well..

$svmname = "EPIC-DC2-NFS01"
Get-NcVolClone -Query @{ Vserver = $svmname; ParentVolume = "Test*"} |ForEach-Object {
$currentClone = Get-NcVolClone -Query @{ Vserver = $svmname; ParentVolume = $_.ParentVolume} | Get-NcVol
$currentClone | Dismount-NcVol -Confirm:$false | Set-NcVol -Offline -Confirm:$false | Remove-NcVol -Confirm:$false

# Get Snapshot
$newestSnap = Get-NcVol -Vserver $svmName -Name $_.ParentVolume | Get-NcSnapshot | Sort-Object -Property Created -Descending | Select-Object -First 1

# create the volume clone
    $splat = @{
        # the SVM to use for the clone...the same as the source volume
        'Vserver' = $svmName;
        
        # the name of the new volume
        'CloneVolume' = "$($_.ParentVolume)_clone";
# the parent SVM
        'ParentVserver' = $svmName;
# the source volume
        'ParentVolume' = $_.ParentVolume;
# the source snapshot
        'ParentSnapshot' = $newestSnap.Name
# thin provision
        'SpaceReserve' = "none";
# junction at the new volume name, not needed if using LUNs
        'JunctionPath' = "/$($_.ParentVolume)_clone"
# make sure it's an active junction, not needed if using LUNs
        'JunctionActive' = $true;
}
    
    New-NcVolClone @splat

# not included, making a LUN in the volume available
}
PS C:\WINDOWS\system32> $splat

Name                           Value                                                                                                                                                                                                                                               
----                           -----                                                                                                                                                                                                                                               
JunctionPath                   /Test3_clone                                                                                                                                                                                                                                        
ParentVolume                   Test3                                                                                                                                                                                                                                               
JunctionActive                 True                                                                                                                                                                                                                                                
SpaceReserve                   none                                                                                                                                                                                                                                                
Vserver                        EPIC-DC2-NFS01                                                                                                                                                                                                                                      
ParentVserver                  EPIC-DC2-NFS01                                                                                                                                                                                                                                      
CloneVolume                    Test3_clone                                                                                                                                                                                                                                         
ParentSnapshot                 clone_Test3_clone.2    
PS C:\WINDOWS\system32> New-NcVolClone @splat
New-NcVolClone : Extra input: junction-active; Extra input: junction-path
At line:1 char:1
+ New-NcVolClone @splat
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (172.28.220.102:NcController) [New-NcVolClone], EINVALIDINPUTERROR
    + FullyQualifiedErrorId : ApiException,DataONTAP.C.PowerShell.SDK.Cmdlets.Volume.NewNcVolClone
 

donny_lang
5,759 Views

Hmm, in that case I might leave the JunctionActive and JunctionPath parameters out of the splat and use the Mount-NcVol command to junction the FlexClone after it has been created. Found a couple posts that indicate there was a bug in older versions of the PSTK, might have not gotten fixed in newer versions. 

 

 

JasonKennedy
5,747 Views

Yep, I was just replying to say the same thing.. The Mount-NcVol gives the same error with more details.. All this work, and crap! Haha...

 

The workaround (If you don't have too much code, because you're limited) is to connect to the data vserver directly. Bamm! It worked as expected.

 

I do appreciate your help... 

 

PS C:\WINDOWS\system32> Mount-NcVol -Name Test_clone -JunctionPath /Test_clone -JunctionActive $true
Mount-NcVol : 
===================================================================================
| This cmdlet must be directed to a data vserver.  You are currently connected    |
| to the cluster admin vserver.  See the Toolkit web docs (Show-NcHelp) or online |
| help (Get-Help Connect-NcController -Examples) to learn more about directing    |
| Toolkit cmdlets to a cluster or data vserver as required by Data ONTAP.         |
===================================================================================
At line:1 char:1
+ Mount-NcVol -Name Test_clone -JunctionPath /Test_clone -JunctionActiv ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (172.28.220.102:NcController) [Mount-NcVol], Exception
    + FullyQualifiedErrorId : NcVserverCmdlet,DataONTAP.C.PowerShell.SDK.Cmdlets.Volume.MountNcVol

JasonKennedy
5,746 Views

and by the way, that command is

 

Connect-NcController "Controller" -Vserver "vservername"

donny_lang
5,725 Views

Glad you got it sorted!

Public