Home > Command Line > SnapMirror Setup Script

SnapMirror Setup Script

March 14th, 2010

I had the task of replicating an existing customers filer to their new DR system. This was quite a large system, and as much as creating SnapMirrors isn’t particularly complex, it is time consuming. So as with many things I do, I wrote a script to help my achieve this task quicker, and go have yet another coffee.

You’ll need pre-shared keys setup (as ever), but the rest is prompted for. There’s no data validation (no surprise). The script will output 4 text files, one for creating/restricting all the volumes, one for the “snapmirror.conf”, on to be used in place of “snapmirror.conf” while you are doing the baseline initialization, and finally one to actually initialize the snapmirrors. There’s no intelligence around concurrent streams, so initialization is still a bit of a juggling act and waiting game.

Please let me know if you find this useful.

#!/bin/bash

echo “Please enter the name of the PRIMARY filer: ”
read PRI_FILER

echo “Please enter the name of the DR filer: ”
read DR_FILER

ConnectString=”ssh -c 3des”
#ConnectString=”rsh”

SnapMirrorHour=22
SnapMirrorMinute=0
SnapMirrorStagger=5

echo “” > ${DR_FILER}_filer_volumes.txt
echo “” > ${DR_FILER}_snapmirror.conf
echo “” > ${DR_FILER}_sm_initialize.txt
echo “” > ${DR_FILER}_snapmirror_init.conf

for AGGR in `${ConnectString} $PRI_FILER “aggr status” | awk ‘$2!~/State/{print $1}’`
do
 SIZE=`${ConnectString} $PRI_FILER “df -Ah $AGGR” | sed ‘s/\([0-9][KMGT]\)B/\1/g’ | awk ‘$1!~/.snapshot|Aggregate/{print $2}’`
 for VOL in `${ConnectString} $PRI_FILER “aggr show_space $AGGR” | awk ‘$1!~/Space/{print $0}’ | awk ‘$4~/volume|file|none/{print $1}’`
 do
  echo “vol create ${VOL} -s none ${AGGR} ${SIZE} ” >> ${DR_FILER}_filer_volumes.txt
  echo “vol restrict ${VOL}” >> ${DR_FILER}_filer_volumes.txt
  echo “snapmirror initialize -S ${PRI_FILER}:${VOL} ${DR_FILER}:${VOL}” >> ${DR_FILER}_sm_initialize.txt
  echo “${PRI_FILER}:${VOL} ${DR_FILER}:${VOL} – ${SnapMirrorMinute} ${SnapMirrorHour} * *” >> ${DR_FILER}_snapmirror.conf
  echo “${PRI_FILER}:${VOL} ${DR_FILER}:${VOL} – – – – -” >> ${DR_FILER}_snapmirror_init.conf

  SnapMirrorMinute=`expr $SnapMirrorMinute + $SnapMirrorStagger`

  if [ $SnapMirrorMinute -gt 58 ]
  then
   SnapMirrorMinute=0
   SnapMirrorHour=`expr $SnapMirrorHour + 1`
  fi
  if [ $SnapMirrorHour -gt 23 ]
  then
   SnapMirrorHour=0
  fi
 done
done

Command Line , , , ,

  1. davis
    | #1

    Awesome script. This is just the thing we need … the exact commands for getting this up and running as quickly as possible.

    This is the first time I’ve set up SnapMirror and I have one question. When you’re running through the loop to populate your ‘${DR_FILER}_filer_volumes.txt’ file it looks like you’re going to create every volume with the size of the parent ${AGGR} on the ${PRI_FILER}. Is that right?

    For example, my ${PRI_FILER} has one aggregate titled aggr_sas with a size of 2850G. (It has a shelf attached to it with an aggr titled aggr_sata but that’s not going to be part of the mirrored data.) I have 5 volumes: vol0 (the OS), vol_swap, vol_win2003, vol_win2008, and vol_linux. If I’m reading your script properly, each of these volumes will be added to ${DR_FILER}_filer_volumes.txt with a size of 2850G.

    Is that correct?

  2. | #2

    Yes, basically what happens is the volume gets thin provisioned to the size of the aggregate (the script does “vol create -s none ” which sets the volume space reservation to none). This allows it to grow dynamically as you grow the primary volumes, so makes your life a little easier. SnapMirror over-rides the thin provisioning setting and the volume will appear to match the primary site volume size, however in reality the underlying volume is larger and so can dynamically grow. The only caveat is that you monitor the space usage on your DR system!

  3. davis
    | #3

    @Chris Kranz
    Thanks for your quick reply … and that wicked sick script! You’ve helped me out quite a bit.

  4. markyMting
    | #4

    Where should this script be run from?

  5. | #5

    The script was written in Linux BASH, so ideally you’d run it from a Linux box of some variety. It may work on other *NIX flavours, but I haven’t tested this.

  1. No trackbacks yet.



This site is not affiliated or sponsored in anyway by NetApp or any other company mentioned within.
%d bloggers like this: