ONTAP Discussions

dataontap module - using powershell to invoke abort on all active snapmirror sessions

thaddad
1,259 Views

I have  a script that can quiesce or abort on a single relationship  (Invoke-NcSnapmirrorAbort...or Quiesce)

My goal is to have  is to Invoke_ .... Abort on all volumes (active replication sessions).  Can I supply a global value  to  DESTINATION to acccomplish this...or do i have to run the abort against each relationship?  Or how? thanks

We want to automate a "kill" for all active sessions!

 

Heres the command syntax for abort ..hope you can read it. 

 

thaddad_1-1715017083312.png

 

 

2 REPLIES 2

mbeattie
608 Views

Hi,

 

Here's a script that using the private REST CLI to enumerate all snapmirror relationships that are in a transferring state and abort them.

 

Param(
    [Parameter(Mandatory = $True, HelpMessage="The Destination Cluster name or IP Address")]
    [String]$Cluster,
    [Parameter(Mandatory = $False, HelpMessage = "The Credentials to authenticate to ONTAP")]
    [System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
Function Get-OntapAuthorization{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to the ONTAP cluster")]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.PSCredential]$Credential
    )
    #'--------------------------------------------------------------------------
    #'Set the authentication header to connect to the cluster.
    #'--------------------------------------------------------------------------
    $auth    = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Credential.UserName + ':' + $Credential.GetNetworkCredential().Password))
    $headers = @{
        "Authorization" = "Basic $auth"
        "Accept"        = "application/json"
        "Content-Type"  = "application/json"
    }
    Return $headers;
}#'End Function Get-OntapAuthorization.
#'------------------------------------------------------------------------------
Function Invoke-OntapRestCli{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $True, HelpMessage = "The Cluster Name or IP Address")]
        [String]$Cluster,
        [Parameter(Mandatory = $True, HelpMessage = "The REST API Method to Invoke")]
        [ValidateSet("get","patch","post","delete")]
        [String]$Method,
        [Parameter(Mandatory = $False, HelpMessage = "The JSON payload used for creating or modifying an object")]
        [String]$Body,
        [Parameter(Mandatory = $True, HelpMessage = "The URI to invoke")]
        [String]$Uri,
        [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to the Cluster")]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.PSCredential]$Credential
    )
    #'--------------------------------------------------------------------------
    #'Exit if the body is not provided when calling the post or patch method.
    #'--------------------------------------------------------------------------
    If(($Method -eq "post" -Or $Method -eq "patch") -And ($Null -eq $Body)){
        Write-Warning -Message "The body parameter must be provided when invoking the patch or post method"
        Return $Null;
    }
    #'--------------------------------------------------------------------------
    #'Add the CLI privilege Level to the command and set the Authentication header.
    #'--------------------------------------------------------------------------
    $headers = Get-OntapAuthorization -Credential $Credential
    #'--------------------------------------------------------------------------
    #'Invoke the command via the private REST CLI.
    #'--------------------------------------------------------------------------
    Try{
        If($Method -eq "post" -Or $Method -eq "patch"){
            $bodyJson = $body | ConvertFrom-Json | ConvertTo-Json -Compress -Depth 100
            $response = Invoke-RestMethod -Method $Method -Body $bodyJson -Uri $Uri -Headers $headers -ErrorAction Stop
        }Else{
            $response = Invoke-RestMethod -Method $Method -Uri $Uri -Headers $headers -ErrorAction Stop
        }
        Write-Host "Invoked ""$Method"" on URI`: $Uri"
        Write-Host "JSON Payload`: $bodyJson"
    }Catch{
        Write-Warning -Message $("Failed Invoking ""$Method"" on URI`: ""$Uri"". Error " + $_.Exception.Message)
        Return $Null;
    }
    Return $response;
}#'End Function Invoke-OntapRestCli.
#'------------------------------------------------------------------------------
#'Enumerate SnapMirror transfers.
#'------------------------------------------------------------------------------
[Int]$errorCount = 0
[String]$uri     = "https://$cluster/api/private/cli/snapmirror?fields=state,status&status=transferring"
Try{
    $transfers = Invoke-RestMethod -Uri $uri -Method Get -Credential $credential -ErrorAction Stop
    Write-Host "Enumerated SnapMirror Transfers for cluster ""$Cluster"" using URI ""$uri"""
}Catch{
    Write-Warning $("Failed Enumerating SnapMirror Transfers for cluster ""$Cluster"" using URI ""$uri"". Error " + $_.Exception.Message)
    Exit -1
}
#'------------------------------------------------------------------------------
# Iterate through each SnapMirror transfer and abort it.
#'------------------------------------------------------------------------------
If($Null -ne $transfers){
    ForEach($record In $transfers.records){
        [String]$source = $record.source_path
        [String]$target = $record.destination_path
        [String]$uri    = "https://$cluster/api/private/cli/snapmirror/abort"
        $snapmirror = @{
           "source-path"      = $source;
           "destination-path" = $target
        }
        $body = $snapmirror | ConvertTo-Json
        Try{
            $response = Invoke-OntapRestCli -Cluster $Cluster -Uri $uri -Method Post -Body $body -Credential $credential -ErrorAction Stop
            Write-Host "Successfully aborted SnapMirror using URI`: $uri"
        }Catch{
            Write-Warning -Message $("Failed aborting SnapMirror Transfer using URI`: $uri. Error " + $_.Exception.Message)
            [Int]$errorCount++
        }
        Write-Host $response
    }
}Else{
    Write-Host "There are no snapmirror transfers on cluster ""$cluster"""
}
If($errorCount -eq 0){
   Write-Host "Completed Successfully"
}Else{
   Write-Host "Completed with $errorCount Errors"
}
#'------------------------------------------------------------------------------

 

Syntax:

 

PS C:\Scripts\PowerShell\Projects\AbortSnapMirrorTransfers> $credentials = Get-Credential -Credential admin
PS C:\Scripts\PowerShell\Projects\AbortSnapMirrorTransfers> .\AbortSnapMirrorTransfers.ps1 -Cluster 192.168.100.3 -Credential $credentials
Enumerated SnapMirror Transfers for cluster "192.168.100.3" using URI "https://192.168.100.3/api/private/cli/snapmirror?fields=state,status&status=transferring"
Invoked "Post" on URI: https://192.168.100.3/api/private/cli/snapmirror/abort
JSON Payload: {"source-path":"vserver1:","destination-path":"vserver1_dr:"}
Successfully aborted SnapMirror using URI: https://192.168.100.3/api/private/cli/snapmirror/abort
Completed Successfully

 

Hope this helps

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Ashun
55 Views

hi

 

Stops ongoing transfers for a SnapMirror relationship.

C:\PS>Invoke-NcSnapmirrorAbort VxeRubble://costea02/unitTestLunsSM

Abort any SnapMirror transfers to destination 'VxeRubble://costea02/unitTestLunsSM'.

 

Disables future transfers to a SnapMirror destination.

C:\PS>Invoke-NcSnapmirrorQuiesce //costea02/unitTestLunsSM -Passthru

Quiesce the SnapMirror with destination '//costea02/unitTestLunsSM' and display the SnapMirror object.

 

SourceLocation DestinationLocation Status MirrorState
-------------- ------------------- ------ -----------
VxeRubble://costea01/unitTestLuns VxeRubble://costea02/unitTestLunsSM quiesced snapmirrored

 

C:\PS>$q = Get-NcSnapmirror -Template
$q.SourceVserver = "beam01"
Invoke-NcSnapmirrorQuiesce -Query $q

Quiesce all snapmirror relationships for source vserver beam01.

 

SuccessCount : 1
FailureCount : 0
SuccessList : {beam01:luns --> beam02:luns}
FailureList : {}

Public