ONTAP Discussions

Powershell script to resize snapmirror destinations?

dearmon
2,505 Views

I'm still very much a novice with Powershell, so writing a script like this is likely to take a lot of my time - therefore, I figured I'd throw it out there and see if anyone had already written one like this or might have a good one that I could use as a "jumping off point".  I have a customer that constantly has problems with SnapMirror relationships failing to transfer because the source volume has autosize enabled and grows beyond the size of the destinaton volume.  This customer is scared to death of thin provisioning, due to a bad experience with a prior storage vendor.  They've asked me to come up with a way for them to quickly and easily resize their sm dest volumes.  I figure to do it like this:

 

1.  Get a list of the sm dest vols using get-nasnapmirror

2.  Get the size of the sm dest vols

3.  Get a list of the sm src vols

4.  Get the size of the sm src vols

5.  Compare the size of the sm dest vols to the sm src vols

6.  If sm dest < sm src, then resize sm dest to the same size as sm src

7.  Update snapmirror

 

Any sugestions would be greatly appreciated.

 

-Matt

2 REPLIES 2

docwebster
2,505 Views

Did you ever find an answer?  I'm actually working on this very thing.  I have an alpha-script.  It worked as a proof of concept, but I'm not positive it's ready for Prime Time.  If you're interested, let me know.

docwebster
2,505 Views

OK, I've refined my script a bit.  I realize this question is about a year and a half old, but I'm answering it anyway.

This script is provided as-is with no warranty or guarantee.  I've not tested it beyond my own environment.  I assume no liability or responsibility for its use.  That being said, I hereby present:

# resizemirs.ps1

# Copyright © 2012, Jim Haddad

#

# This script will query mirror pairs between filers

# to check the source and destination sizes of each volume.

# If the destination volume is smaller than the source volume,

# The destination volume will be resized.

#

function GetVolSize ($Filer, $VolName) {

   # Connect to the specified filer.

   # Get the size of the source volume in bytes.

   $FilerObj = connect-nacontroller $Filer -rpc

   $VolSize = Get-NaVolSize $VolName

   $VolBytes = $VolSize.VolumeSize

   return $VolBytes

} # function GetSourceSize

function GetNewVolSize ($SourceVolBytes) {

   # Starting with the size of the source volume,

   # add on an additional 3% to pad the new size

   # for the destination.

   # Convert that to megabytes, and round it off.

   # Add an "m" to the end of the string to match

   # the required syntax for sending the command

   # to the Filer.

   $Padding = $SourceVolBytes*.03

   $NewVolBytes = $SourceVolBytes + $Padding

   $NewVolMB = $NewVolBytes/(1024*1024)

   $NewVolRounded = ([math]::round($NewVolMB,0))

   $NewVolSize = [string]::join('',($NewVolRounded,'m'))

   return $NewVolSize

} # function GetNewSize

function SetNewVolSize ($Filer, $VolumeName, $NewVolSize) {

   $FilerObj = connect-nacontroller $Filer -rpc

   Set-NaVolSize $VolumeName $NewVolSize

} # function SetNewVolSize

# Main {

   # Get the SnapMirror status for each filer.

   # For each SnapMirror, parse out the source and destination filers and volumes.

   # Call the function to get the size for each source volume.

   # Call the function to get the size for each destination volume.

   # If the destination size is less than the source size:

   #    Call the function to calculate the new size for the destination volume.

   #    Set the destination volume to the new size.

   Import-Module DataONTAP

   $Report = @()

   $BlankLine = ""

  

   #### Insert your own filer names in the following line:

   $FilerList = "filer1","filer2","filer3"

   ####

  

   Foreach ($Filer in $FilerList) {

      $FilerObj = connect-nacontroller $Filer -rpc

      $FilerMirrors = Get-NaSnapMirror

      Foreach ($Pair in $FilerMirrors) {

         $Source = $Pair.source.split(":")

         $SourceFiler = $Source[0]

         $SourceVolName = $Source[1]

         $SourceVolBytes = GetVolSize $SourceFiler $SourceVolName

         $ReportLine1 = $SourceVolName + ": " + $SourceVolBytes

        

         $Destination = $Pair.destination.split(":")

         $DestFiler = $Destination[0]

         $DestVolName = $Destination[1]

         $DestVolBytes = GetVolSize $DestFiler $DestVolName

         $ReportLine2 = $DestVolName + ": " + $DestVolBytes

        

         if ($DestVolBytes -lt $SourceVolBytes) {

            $NewVolSize = GetNewVolSize $SourceVolBytes

            $ReportLine3 = "Destination volume will be resized to: " + $NewVolSize

            SetNewVolSize $DestFiler $DestVolName $NewVolSize

         } else {

            $ReportLine3 = "Destination Volume Size is OK."

         } # if ($DestVolBytes -lt $SourceVolBytes)

         $Report = $Report + $ReportLine1 + $ReportLine2 + $ReportLine3 + $BlankLine

      } # Foreach ($Pair in $MirrorPairs)

   } # Foreach ($Filer in $FilerList)

   echo $Report > ResizeReport.txt

  

# } Main

Public