Microsoft Virtualization Discussions

Take clone name and check current snapshopt name

ernest_brant
3,716 Views

Hello All

I am not a NetApp engineer, I am starting to write powershell scripts and getting on OK,

However can someone please give me a bit of assistance on the following...

lets say I have a clone of a LUN called Clone_XXX this clone was created a few days ago and the original LUN now has several move snapshots.

can some one please give me a suggestion or two on how to check if the clone in question is still based on the most current snapshot? or if one or more newer snapshots have taken place since the original clone (assuming you do not know the snapshot schedule)

Thanks all

Ernie

ErnestBrant@Hotmail.co.uk

3 REPLIES 3

lovik_netapp
3,716 Views

I am not a powershell guy so I don't know how to achieve this through scripts however if want to see this on SSH/RSH/console, you can run the command "snap list -b <parent volume>", where parent volume is the volume which was used to create a clone volume and from the list of snapshot the clone snapshot will have busy status next to its name, you can also check the parent volume name with command "vol status <clone volume name>"

Cheers,

ernest_brant
3,716 Views

Thanks for the reply Lovik

that is the sort if info, I need. I can then work out the powershell commands from here, I will let you know the relevent powershell, now I have the idea and figured it out.

Thanks again

Ernest

paleon
3,716 Views

The cmdlets to use will be Get-NaVol and Get-NaSnapshot.

Get-NaVol returns an array of objects of type VolumeInfo.  VolumeInfo objects include a property named "CloneParent".  This property returns an array of objects of type CloneParentInfo.  I'm not sure whether it is possible for a volume clone to have more than parent, I'm not sure why this property returns an array.  Perhaps clones of clones will return a different result.  You may want to do some proof-of-concept testing on this point.  The CloneParentInfo object includes properties named "ParentSnapshotName" and "ParentVolumeName".


Get-NaSnapshot returns an array of SnapshotInfo objects for a given volume.  Depending on how busy the NetApp controller is, it is very possible for this cmdlet to timeout.  I, therefore, recommend that you do some error handling around this step.  Error handling is not shown in this code.  Each SnapshotInfo object contains properties including "Created", "Dependency", and "Name".  For easy of coding, I have assumed that only snapshots with no dependencies are usable.  (I did this to avoid grabbing temporary snapshots which are created for SnapMirror, SnapVault, A-SIS, etc.).

Here is the code:

$netapp = $hilav1file5

#Get a list of volumes and sort by name
$vols   = Get-NaVol -Controller $netapp | Sort-Object -Property "Name"

#Filter for volumes whose names begin with "clone_"
$cloneVols = $vols | Where-Object {$_.Name -match "^clone_"}

foreach ($vol in $CloneVols) {
    if ($vol.CloneParent -ne $null) {
        foreach ($parent in $cloneParent) {
            #Instantiate $snaps and $parentVol as $null to eliminate stale values from the last iteration
            $snaps              = $null
            $parentVol          = $null

            $parentVolName      = $parent.ParentVolumeName
            $parentSnapName     = $parent.ParentSnapshotName
            $parentVol          = Get-NaVol -Controller $netapp | Where-Object {$_.name -eq $parentVolName}
            if ($parentVol -ne $null) {
                $snaps              = Get-NaSnapshot -Controller $netapp -TargetName $parentVol.Name | Sort-Object -Property "Created" -Descending
                if ($snaps -ne $null) {
                    #Snapshots used by other processes like SnapMirror, SnapVault, A-SIS, etc. should be excluded.
                    $usableSnaps        = $snaps | Where-Object {$_.Dependency -eq ""}
                    if ($usableSnaps -ne $null) {
                        $parentSnap         = $snaps | Where-Object {$_.Name -eq $parentSnapName}
                        if ($parentSnap.Created -lt $usableSnaps[0].Created) {
                            write-host "Newer snapshot exists for $($vol.name).  The snapshot is named $($usableSnaps[0].name)"
                        }
                    }
                }
            }
        }
    }
}

Public