Active IQ Unified Manager Discussions

Powershell SnapMirror

fmg_netapp1
10,837 Views

Hi, I have done a snapmirror between clusters, and feel fairly comfortable with the process, what i was wanting to know was how do i find out the status of a snapmirror in progress, how much data has been moved and how long the process has been running. I know via command line how to do it, but could anyone show me how to do it in powershell. 

 

we are currently on a fas8020 running 8.3.1. Any help most appreciated. 

7 REPLIES 7

geringer
10,824 Views

Have you looked at the Get-NcSnapMirror cmdlet?  I believe that if you speciffy only one relationship it will return all of the attributes for that relationship.  I do not have a working lab to test that, but it should be quick to check.  The Get-NcSnapMirrorHistory may also have the information that you are looking for, but I am not sure if it will return it for a running update.

fmg_netapp1
10,716 Views

Hi Geringer, though the command is useful it doesnt provide the detail that i need. I can see how this command can be used to monitor mirror history of comms. I will definately be using this in the future in my toolkit.

 

asulliva
10,705 Views

I think something like this will work to return the amount of data transferred and time elapsed.  I don't have any active snapmirror relationships to test with, so I can't say for sure...

 

Get-NcSnapmirror -Query @{ RelationshipStatus = "transferring" } | Select-Object SourceLocation,DestinationLocation, `
    @{'N'='GB Transferred'; 'E'={ [Math]::Round($snapmirror.TotalTransferBytes / 1gb, 2) } }, `
    @{'N'='Min Elapsed'; 'E'={ [Math]::Round((New-TimeSpan -Seconds $snapmirror.TotalTransferTimeSecs).Minutes, 2) } }

Andrew

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

fmg_netapp1
10,676 Views

Hi, Thanks for shwoing me this, it seems as if this could be it. I will set up some data to transfer and then gt back to you with some results. Many thanks again. 

fmg_netapp1
10,638 Views

Hi, Just set another snapmirror to go now, and i can see the results via ssh. 

 

Using the command above, in " GB Transferred Min Elapsed" i just aget a 0 all the way down. There are names in "SourceLocation" and  "DestinationLocation" but nothing in the last column, also the snapmirror that i have set of cannot be seen anywhere in this command. 

 

Not sure what more to add really 😞

abhit
10,604 Views

There are quite some powershell commands for snapmirror written in WFA.

Try to use these commands by changing a little.

I have copied some of the powershell commands below.

 

 

1.Remove SnapMirror

 

param (
[parameter(Mandatory=$true, HelpMessage="Source Cluster")]
[string]$SourceCluster,

[parameter(Mandatory=$true, HelpMessage="Destination Cluster")]
[string]$DestinationCluster,

[parameter(Mandatory=$true, HelpMessage="Source Storage Virtual Machine")]
[string]$SourceVserver,

[parameter(Mandatory=$true, HelpMessage="Destination Storage Virtual Machine")]
[string]$DestinationVserver,

[parameter(Mandatory=$true, HelpMessage="Source Volume")]
[string]$SourceVolume,

[parameter(Mandatory=$true, HelpMessage="Destination Volume")]
[string]$DestinationVolume,

[parameter(Mandatory=$true, HelpMessage="Destination Cluster IP Address")]
[string]$DestinationClusterIP
)

# connect to controller
Connect-WfaCluster $DestinationClusterIP

$vsm = Get-NcSnapmirror -SourceCluster $SourceCluster -DestinationCluster $DestinationCluster -SourceVserver $SourceVserver -DestinationVserver $DestinationVserver -SourceVolume $SourceVolume -DestinationVolume $DestinationVolume -ErrorAction Stop

if($vsm -and $vsm.Status -eq "transferring")
{
throw "Cannot remove relationship as it is currently transferring."
}

Get-WFALogger -Info -message $("Removing SnapMirror relationship between " + $SourceCluster + ":"+ $SourceVserver + "/"+ $SourceVolume + "and" + $DestinationCluster + ":"+ $DestinationVserver + "/"+ $DestinationVolume )
Remove-NcSnapmirror -SourceCluster $SourceCluster -DestinationCluster $DestinationCluster -SourceVserver $SourceVserver -DestinationVserver $DestinationVserver -SourceVolume $SourceVolume -DestinationVolume $DestinationVolume -Confirm:$false -ErrorAction Stop

 

 

=====

2. Wait for SnapMirror initialization or resync

 

 

param (
[parameter(Mandatory=$true, HelpMessage="Source Cluster")]
[string]$SourceCluster,

[parameter(Mandatory=$true, HelpMessage="Destination Cluster")]
[string]$DestinationCluster,

[parameter(Mandatory=$true, HelpMessage="Source Storage Virtual Machine")]
[string]$SourceVserver,

[parameter(Mandatory=$true, HelpMessage="Destination Storage Virtual Machine")]
[string]$DestinationVserver,

[parameter(Mandatory=$true, HelpMessage="Source Volume")]
[string]$SourceVolume,

[parameter(Mandatory=$true, HelpMessage="Destination Volume")]
[string]$DestinationVolume,

[parameter(Mandatory=$true, HelpMessage="Cluster IP")]
[string]$ClusterIP,

[parameter(Mandatory=$false, HelpMessage="Approximate transfer size in MB. Used to calculate the percentage progress for SnapMirror relationships on Clustered ONTAP 8.2 or later.")]
[long]$TransferSize
)

function Wait-For-Initialization-V1
{
# Use query template so ONTAP will not have to return all the jobs, but only the relevant ones (unfortunately its not currently possible to filter by matching JobDescription)
$query = Get-NcJob -Template
$query.JobType = "Transfer-Initialize"

# Get the latest job which initializes the vsm relationship
$job = Get-NcJob -Query $query | where {$_.JobDescription -eq "snapmirror initialize of destination " + $DestinationCluster + "://" + $DestinationVserver + "/" + $DestinationVolume } | Sort-Object -Descending -Property JobId | Select-Object -First 1

if(!$job)
{
# No job was found, it could be that the job was purged or that no job was created
# because the vsm relationship is already in 'snapmirrored' state.
# Checking that the vsm relationship is in 'snapmirrored' state
$vsm = Get-NcSnapmirror -SourceCluster $SourceCluster -DestinationCluster $DestinationCluster -SourceVserver $SourceVserver -DestinationVserver $DestinationVserver -SourceVolume $SourceVolume -DestinationVolume $DestinationVolume -ErrorAction SilentlyContinue

if(!$vsm)
{
Get-WFALogger -Info -message $("Cannot find the SnapMirror relationship. Failing the command.")
Set-WfaCommandProgress -Total 1 -Current 0 -ProgressPercentage 100 -Note "Cannot find the SnapMirror relationship"
throw "Failed to initialize SnapMirror relationship between " + $SourceCluster + "://"+ $SourceVserver + "/"+ $SourceVolume + " and " + $DestinationCluster + "://"+ $DestinationVserver + "/"+ $DestinationVolume
}
else
{
if($vsm.MirrorState -ne "snapmirrored")
{

# Job is not found and relationship is not in 'snapmirrored' state..
# verify that the paramters passed to this command are matching the parameters
# supplied to the Create VSM command. if yes, then the initialization failed.
# if not, it means this command was executed with wrong parameter values and
# should be executed with the correct ones.

Get-WFALogger -Info -message $("SnapMirror initialization job was not found and relationship is not in 'snapmirrored' state.")
Set-WfaCommandProgress -Total 1 -Current 0 -ProgressPercentage 100 -Note "SnapMirror initialization job was not found and relationship is not in 'snapmirrored' state."
throw "Failed to initialize SnapMirror relationship between " + $SourceCluster + "://"+ $SourceVserver + "/"+ $SourceVolume + " and " + $DestinationCluster + "://"+ $DestinationVserver + "/"+ $DestinationVolume
}
else
{
Get-WFALogger -Info -message $("SnapMirror relationship is already initialized.")
Get-WFALogger -Info -message $("SnapMirror initialization completed successfully.")
Set-WfaCommandProgress -Total 1 -Current 1 -ProgressPercentage 100 -Note "SnapMirror initialization completed successfully."
}
}

}
else
{
if($job.JobState -eq "success")
{
Get-WFALogger -Info -message $("SnapMirror initialization completed successfully.")

# Volume move already completed - mark it 100% completed
Set-WfaCommandProgress -Total 1 -Current 1 -ProgressPercentage 100 -Note $job.JobProgress
}
elseif($job.JobState -eq "running")
{
Set-WfaCommandProgress -Total 1 -Current 0 -ProgressPercentage 0 -Note $job.JobProgress
Get-WFALogger -Info -message $("Initialization job stauts - " + $job.JobProgress)
}
elseif($job.JobState -eq "failure" -and $job.JobCompletion.Contains("already initialized"))
{
Get-WFALogger -Info -message $("SnapMirror relationship is already initialized.")
Get-WFALogger -Info -message $("SnapMirror initialization completed successfully.")
# Volume move already completed - mark it 100% completed
Set-WfaCommandProgress -Total 1 -Current 1 -ProgressPercentage 100 -Note $job.JobProgress
}
else
{
Get-WFALogger -Info -message $("SnapMirror initialization failed.")
Set-WfaCommandProgress -Total 1 -Current 0 -ProgressPercentage 100 -Note $job.JobProgress
throw "Failed to initialize SnapMirror relationship between " + $SourceCluster + "://"+ $SourceVserver + "/"+ $SourceVolume + " and " + $DestinationCluster + "://"+ $DestinationVserver + "/"+ $DestinationVolume
}
}
}

# Wait for either SnapMirror initialize or resync to complete.
function Wait-For-Initialization-V2($relationship)
{
if ($relationship.IsHealthy -eq "true") {
if($relationship.MirrorState -eq "snapmirrored" -and $relationship.RelationshipStatus -eq 'idle' )
{
$bytesTransferredMessage = "Transferred " + $relationship.LastTransferSize + " bytes."
Get-WFALogger -Info -message $("SnapMirror initialization or resync completed successfully. $bytesTransferredMessage")
Set-WfaCommandProgress -Total 1 -Current 1 -ProgressPercentage 100 -Note $bytesTransferredMessage
}
elseif (($relationship.MirrorState -eq 'uninitialized' -or $relationship.MirrorState -eq 'snapmirrored') -and
( $relationship.RelationshipStatus -eq 'transferring' -or
$relationship.RelationshipStatus -eq 'quiescing' -or
$relationship.RelationshipStatus -eq 'queued' -or
$relationship.RelationshipStatus -eq 'preparing' -or
$relationship.RelationshipStatus -eq 'finalizing'
))
{
$percentComplete = if ($TransferSize -and $relationship.RelationshipProgress -and $TransferSize -ne 0) {($relationship.RelationshipProgress*100)/($TransferSize*1024*1024)} else {0}
#
# Used size is only an approximation and sometimes we may have stale
# used size. So guard against the percentage going above 100.
#
if ($percentComplete -gt 99) {
$percentComplete = 99
}
$progressMessage = "Transferred " + $relationship.RelationshipProgress + " bytes so far."
Get-WFALogger -Info -message $("SnapMirror initialization or resync in progress. $progressMessage")
Set-WfaCommandProgress -Total 1 -Current 0 -ProgressPercentage $percentComplete -Note $progressMessage
}
else {
$relationshipStateMessage = "Relationship state is '" + $relationship.MirrorState + "' (" + $relationship.RelationshipStatus + "). " + $relationship.LastTransferError
Get-WFALogger -Info -message $("SnapMirror initialization or resync failed. $relationshipStateMessage")
Set-WfaCommandProgress -Total 1 -Current 0 -ProgressPercentage 100 -Note $relationshipStateMessage
throw "Failed to initialize or resync SnapMirror relationship between " + $SourceCluster + "://"+ $SourceVserver + "/"+ $SourceVolume + " and " + $DestinationCluster + "://"+ $DestinationVserver + "/"+ $DestinationVolume + ". " + $relationshipStateMessage
}
}
else {
$ErrorMessage = "SnapMirror is not healthy"
Get-WFALogger -Info -message $("$ErrorMessage")
Set-WfaCommandProgress -Total 1 -Current 0 -ProgressPercentage 100 -Note $ErrorMessage
throw "Failed to initialize or resync SnapMirror relationship between " + $SourceCluster + "://"+ $SourceVserver + "/"+ $SourceVolume + " and " + $DestinationCluster + "://"+ $DestinationVserver + "/"+ $DestinationVolume + ". " + $ErrorMessage
}

}

Get-WFALogger -Info -message $("Handling SnapMirror initialization or resync for relationship between " + $SourceCluster + "://"+ $SourceVserver + "/"+ $SourceVolume + " and " + $DestinationCluster + "://"+ $DestinationVserver + "/"+ $DestinationVolume )

# connect to controller
Connect-WfaCluster $ClusterIP

# Retrieve the relationship to check if it is 8.1-style or 8.2-style
# relationship. This is indicated by the relationship control plane.
# For 8.1-style relationships (control plane V1), there is a job in ONTAP
# whose status we can check. For 8.2-style relationship (control plane V2),
# there is no job. We just wait for the relationship state to
# become 'snapmirrored'.
#

# Temporary workaround to handle an issue in snapmirror-get-iter API for SnapMirror relationships of infinite volume.
# Instead of sending all keys of a SnapMirror relationship (destination-cluster, destination-vserver, destination-volume, source-cluster, source-vserver, source-volume),
# one of the keys destination-volume will not be sent

$TargetVolume = Get-NcVol -Vserver $DestinationVserver -Name $DestinationVolume

if (!$TargetVolume)
{
throw "There is no destination volume with name " + $TargetVolume
}

if($TargetVolume.IsInfiniteVolume)
{
$relationship = Get-NcSnapmirror -SourceCluster $SourceCluster -DestinationCluster $DestinationCluster -SourceVserver $SourceVserver -DestinationVserver $DestinationVserver -SourceVolume $SourceVolume -ErrorAction SilentlyContinue
}
else
{
$relationship = Get-NcSnapmirror -SourceCluster $SourceCluster -DestinationCluster $DestinationCluster -SourceVserver $SourceVserver -DestinationVserver $DestinationVserver -SourceVolume $SourceVolume -DestinationVolume $DestinationVolume -ErrorAction SilentlyContinue
}

if(!$relationship)
{
Get-WFALogger -Info -message $("Cannot find the SnapMirror relationship. Failing the command.")
Set-WfaCommandProgress -Total 1 -Current 0 -ProgressPercentage 100 -Note "Failure"
throw "Failed to initialize SnapMirror relationship between " + $SourceCluster + "://"+ $SourceVserver + "/"+ $SourceVolume + " and " + $DestinationCluster + "://"+ $DestinationVserver + "/"+ $DestinationVolume
}
else
{
#
# 8.1 cluster does not have RelationshipControlPlane field.
# If 8.1 cluster is upgraded to 8.2, RelationshipControlPlane for an
# existing relationships is V1 until the relationship is upgraded to
# SN-style relationship.
#
if(!$relationship.RelationshipControlPlane -or
$relationship.RelationshipControlPlane -eq "v1")
{
Get-WFALogger -Info -message $("Detected 8.1-style relationship. Relationship control plane: " + $relationship.RelationshipControlPlane)
Wait-For-Initialization-V1
}
else
{
Get-WFALogger -Info -message $("Detected 8.2-style relationship. Relationship control plane: " + $relationship.RelationshipControlPlane)
Wait-For-Initialization-V2 -relationship $relationship
}
}

 

xandervanegmond
10,597 Views

You may want to look into the featured post for snapmirror auditlog parser:

 

https://community.netapp.com/t5/Microsoft-Cloud-and-Virtualization-Discussions/PowerShell-SnapMirror-Audit-Log-Parser-for-CDOT/m-p/130304#M5358

 

It does a lot more than what you posted, but you can either take from that script what you need, or you'll find that it is even better than what you wanted :).

 

/Xander

Public