Microsoft Virtualization Discussions

PowerShell cmdlet for consistency groups in clustered Data Ontap

florianf
4,678 Views

I would like to create consistent snapshots on a cDOT system with PowerShell. From the SnapDrive documentation I know that cDOT supports consistency groups, but I can only find consistency group cmdlets for 7-Mode (e.g. New-NaConsistencyGroup, Remove-NaConsistencyGroup and Save-NaConsistencyGroup).

 

For cDOT I found the cmdlet New-NcSnapshotMulti which will create snapshots on multiple volumes, but the cmdlet help for it doesn't mention the snapshots to be consistent.

 

Is there a way to create consistency groups via PowerShell in cDOT? If not, is there any other way to create consistent snapshots in cDOT?

3 REPLIES 3

Aparajita
4,655 Views

Hi Florian,

 

Consistency-group cmdlets have not been implemented for cMode yet. As an alternative, you can run the equivalent CLI commands from PowerShell using Invoke-NaSSH.

 

Hope this helps,

Aparajita

florianf
4,651 Views

Thanks for the hint, but unfortunately consistency group functionality is not available from the cluster shell. It is only available via "cg-start" and "cg-commit" ZAPI calls. Is there a chance this will get implemented into the PowerShell Cmdlets in the near future? Is directly issue ZAPI calls with PowerShell?

florianf
4,589 Views

I got the advice to use Invoke-NcSystemApi and wrote my own Cmdlet. I hope something similar will be available in a future PowerShell Toolkit upgrade.

 

<#
.SYNOPSIS
Creates consistency group for all specified volumes and triggers a snapshot on the consistency group.
.DESCRIPTION
This operation fences the specified volumes in a consistency group and if this succeeds, the snapshot will be committed. Infinite Volumes are not supported for this operation. It is recommended to use the Test-NcSnapshotMulti cmdlet to identify possible errors before using this cmdlet.
.EXAMPLE
New-NcSnapshotConsistencyGroup -Volumes vol1,vol2 -SnapName snap1 -Timeout relaxed -SnapMirrorLabel daily -GetSnapshots -VserverContext svm1
.PARAMETER Volumes
Names of the volumes across which the snapshot is to be created.
.PARAMETER SnapName
Name of the snapshot to be created. The maximum string length is 256 characters.
.PARAMETER Timeout
Timeout selector. Possible vaules are "urgent", "medium" or "relaxed". If no value is specified, the default value is "medium". Following are the timeout values:
urgent: 5 seconds
medium: 7 seconds
relaxed: 20 seconds
Either Timeout or UserTimeout parameters can be used.
.PARAMETER UserTimeout
User specified timeout value in seconds. This option can be set if the user wants to specify timeout value other than the default timeouts. The minimum value for this field is equal to the "urgent" timeout. The maximum timeout which can be specified is 120 seconds.
Either Timeout or UserTimeout parameters can be used.
.PARAMETER SnapMirrorLabel
A human readable SnapMirror label to be attached with the consistency group snapshot copies. Size of the label can be at most 31 characters. This label will be applied as an attribute to the snapshots that are created and will be used by the vaulting system to identify a vaulting scheme.
.PARAMETER GetSnapshots
Specify to output the resulting snapshot objects.
.PARAMETER VserverContext
Vserver to which to direct this command.  If the currently connected controller (as embodied by an NcController object) represents a cluster, there are multiple means to address commands to one of its vservers.  Either set the Vserver field on the NcController object to direct all subsequent commands to that vserver, or supply the VserverContext parameter to an individual cmdlet.  Only cmdlets which may be invoked on vservers offer the VserverContext parameter.
.PARAMETER Controller
A clustered Data ONTAP controller to receive this cmdlet, as embodied by an NcController object.  This parameter is returned by the Connect-NcController cmdlet.  If not specified, the value in the global variable CurrentNcController is used.  In the latter case, if CurrentNcController contains a collection of NcController objects, this cmdlet is invoked on each controller in succession.
.LINK
Test-NcSnapshotMulti
Get-NcSnapshot
#>
function global:New-NcSnapshotConsistencyGroup {
    [CmdletBinding(DefaultParameterSetName="none")]
 
    PARAM (
        [parameter(Mandatory=$True,
                    Position=0,
                    HelpMessage="Names of the volumes across which the snapshot is to be created.",
                    ValueFromPipeline=$True,
                    ValueFromPipelineByPropertyName=$True)][String[]]$Volumes,
        [parameter(Mandatory=$True,
                    Position=1,
                    HelpMessage="Name of the snapshot to be created. The maximum string length is 256 characters.",
                    ValueFromPipeline=$True,
                    ValueFromPipelineByPropertyName=$True)][ValidateLength(1,256)][String]$SnapName,
        [parameter(Mandatory=$False,
                    Position=2,
                    HelpMessage="Specify to output the resulting snapshot objects.",
                    ParameterSetName="Timeout")][ValidateSet("urgent", "medium", "relaxed")][String]$Timeout,
        [parameter(Mandatory=$False,
                    Position=2,
                    HelpMessage="Specify to output the resulting snapshot objects.",
                    ParameterSetName="UserTimeout")][ValidateRange(5,120)][Int]$UserTimeout,
        [parameter(Mandatory=$False,
                    Position=3,
                    HelpMessage="Specify to output the resulting snapshot objects.")][ValidateLength(1,31)][String]$SnapMirrorLabel,
        [parameter(Mandatory=$False,
                    Position=4,
                    HelpMessage="Specify to output the resulting snapshot objects.")][Switch]$GetSnapshots,
        [parameter(Mandatory=$True,
                    Position=5,
                    HelpMessage="Vserver to which to direct this command.  If the currently connected controller (as embodied by an NcController object) represents a cluster, there are multiple means to address commands to one of its vservers.  Either set the Vserver field on the NcController object to direct all subsequent commands to that vserver, or supply the VserverContext parameter to an individual cmdlet.  Only cmdlets which may be invoked on vservers offer the VserverContext parameter.")][String]$VserverContext,
        [parameter(Mandatory=$False,
                    Position=6,
                    HelpMessage="Specify to output the resulting snapshot objects instead of the multicreate result object.")][String]$Controller
    )

    $xmlDoc = New-Object system.Xml.XmlDocument
    $xmlDoc.loadXml("<cg-start><snapshot></snapshot></cg-start>")

    $cgstart = $xmlDoc."cg-start"
    $cgstart.snapshot = $SnapName

    if ($SnapMirrorLabel) {
        $element = $XmlDoc.CreateElement("snapmirror-label")
        $element.InnerText = $SnapMirrorLabel
        $null = $cgstart.AppendChild($element)
    }

    if ($Timeout) {
        $element = $XmlDoc.CreateElement("timeout")
        $element.InnerText = $Timeout
        $null = $cgstart.AppendChild($element)
    }
    elseif ($UserTimeout) {
        $element = $XmlDoc.CreateElement("user-timeout")
        $element.InnerText = $UserTimeout
        $null = $cgstart.AppendChild($usertimeout)
    }

    $volumeselement = $xmlDoc.createElement("volumes")

    foreach ($volume in $Volumes) {
        $element = $XmlDoc.CreateElement("volume-name")
        $element.InnerText = $Volume
        $null = $volumeselement.AppendChild($element)
    }
    $null = $cgstart.AppendChild($volumeselement)

    $result = Invoke-NcSystemApi -RequestXML $xmlDoc -VserverContext $VserverContext -ErrorAction Stop

    if (!$result.results.status -eq "passed") {
        throw "Starting consistent snapshot failed with status " + $result.results.status 
    }

    $xmlDoc = New-Object system.Xml.XmlDocument
    $xmlDoc.loadXml("<cg-commit><cg-id></cg-id></cg-commit>")

    $xmlDoc."cg-commit"."cg-id" = $result.results."cg-id"

    $result = Invoke-NcSystemApi -RequestXML $xmlDoc -VserverContext $VserverContext -ErrorAction Stop


    if (!$result.results.status -eq "passed") {
        throw "Committing consistent snapshot failed with status " + $result.results.status 
    }

    if ($GetSnapshots) {
        foreach ($Volume in $Volumes) {
            $Snapshot = Get-NcSnapshot -Volume $Volume -Vserver $VserverContext -SnapName $SnapName
            Write-Output $Snapshot
        }
    }
}
Public