VMware Cloud Community
MikeAvery
Contributor
Contributor

VCB NetApp RDM LUN Snapshot Script

I remember having to scrounge around for information on the correct way to automate hardware snapshots against NetApp iSCSI RDM LUNs. I found some useful bits and pieces but nothing that I could pick up and use. In the end I wrote my own script using the VMware Infrastructure Perl Toolkit.

It's not pretty, it works. There is room for refinement. I welcome any questions, suggestions, additions, patches or feedback.

Enjoy.

\# vcb-netapp-rdm-snap.pl 0.1.0

\# Copyright (C)2007 Zarlink Semiconductor

\# Michael.Avery @at Zarlink.com

#

#

\# This script is provided in the hopes that it will be useful. It could use

\# some improvements, error checking and refinement. Feel free to do so and

\# submit changes.

#

#This program is free software; you can redistribute it and/or

#modify it under the terms of the GNU General Public License

#as published by the Free Software Foundation; either version 2

#of the License, or (at your option) any later version.

#

#This program is distributed in the hope that it will be useful,

#but WITHOUT ANY WARRANTY; without even the implied warranty of

#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

#GNU General Public License for more details.

#

#You should have received a copy of the GNU General Public License

#along with this program; if not, write to the Free Software

#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

#

#

\# CHANGELOG

\# \----


#

\# --> Version 0.1.0 May 18, 2007

\# - Initial public release

#

################################################################################

\# Automate the process of performing VCB and NetApp Snapshots

\# against RDM LUNs in a VC controlled Datacenter

#

\# The script will automate polling of the VC server for configured VMs within the

\# configured Datacenter and process each one.

#

\# - Connect to VC and inventory the Datacenter

\# - Process each configured vmName

\# - Have VC vcbSnapshot the VM (VC knows which host in a DRS/HA cluster houses the VM)

\# - Perform a hardware snapshot against the VM's volume on the filer

\# - Have VC delete the vcbSnapshot

\# - Disconnect from VC

#

\# A Datacenter with 20 virtual machines normally takes 3-5 minutes to process.

#

#

\# This script requires that the VMware Infrastructure Perl Toolkit is installed

\# and working on the host which "runs" this script.

\# http://sourceforge.net/projects/viperltoolkit

#

#

\# *** IMPORTANT READING ***

#

\# This script has been tested and successfully used in production under the

\# following configuration. This tools works with best practice configurations

\# matching the following configuration. It is NOT guaranteed to work for you.

#

\# * NetApp 3020 cluster - Data ONTAP 7.0.4 or greater

\# * VI 3.x Datacenter (ESX 3.x, VC 2.x, VCB, DRS/HA Cluster)

\# * iSCSI software initiator

\# * volume-per-VM, with virtual access RDM LUNs per disk within the VM.

#

\# - It is assumed that SSH has been configured on ESX hosts and the filer

\# using key based authentication.

#

\# - VM names MUST match the NetApp volume name on the NetApp. If you need

\# to support differing VM and volume names, please feel free to modify this

\# script, and please submit patches.

#

\# Invoke this script through a crontab entry. Here's an example. You will need

\# to change your crontab entry accordingly

#

\# 15 23 * * 2-7 /path/to/vcb-netapp-rdm-snap.pl --host $vc --username $adminuser --password $password

#

################################################################################

#

\# CONFIGURATION OPTIONS

#

\# The hostname of your NetApp Filer

my $filer="";

\# The name of the VC Datacenter containing VMs to snap

my $datacenter="";

\# VC account for performing snapshot operations

\# It is best to use a dedicated account which has snapshot abilities only!

my $adminuser='';

my $password='';

\# VirtualCenter hostname

my $vc="";

\# An ESX host to act from

#

my $esxhost="";

#

\# END CONFIGURATION OPTIONS

#

print "\n\nvcb-netapp-rdm-snap.pl - Virtual Infrastructure Snapshot Utility\n";

print "Copyright (C) 2007 Zarlink Semiconductor\n";

print "vcb-netapp-rdm-snap.pl comes with ABSOLUTELY NO WARRANTY\n\n";

use strict;

use warnings;

use VMware::VIM2Runtime;

use VMware::VILib;

\# read/validate options and connect to the server

Opts::parse();

Opts::validate();

Util::connect();

\# Use Virtual Consolidated Backup facilities

print "Connecting to VirtualCenter server: \[" . $vc . "\] ...";

\# Locate Datacenter in VirtualCenter - Die if not found

my $datacenter_view = Vim::find_entity_view(view_type => 'Datacenter',

filter => \{ name => $datacenter });

if (!$datacenter_view) {

print "FAILED\n";

die "Datacenter '" . $datacenter . "' not found\n";

}

print "OK\n";

\# Command for query of configured VM information

my $cmd = "ssh " . $esxhost . " /usr/sbin/vcbVmName -L 0 -c /tmp/foo -h " . $vc . " -u " . $adminuser . " -p " . $password . " -s any:";

print "Discovering Virtual Machines in Datacenter \[" . $datacenter . "]\n";

my @vmarray=`$cmd`;

\# Now, step through each VM reported and perform VCB and NetApp Snap operations

my $counter = 1;

my $value = "";

my $key = "";

foreach (@vmarray) {

($key, $value) = split(/:/);

  1. Process discovered VMs

if ($key eq "Found VM") {

($key, my $namev) = split(/:/,$vmarray\[$counter + 1]);

chomp $namev;

print "\n\nProcessing VM\[". $namev ."]:";

($key, my $vmidv) = split(/:/,$vmarray\[$counter]);

chomp $vmidv;

print " " . $key . "\[" . $vmidv . "] ";

($key, my $ipv) = split(/:/,$vmarray\[$counter + 3]);

chomp $ipv;

print $key . "\[" . $ipv . "]\n";

  1. First clean up stale VCB snapshot, if any

$cmd = "ssh ".$esxhost." /usr/sbin/vcbSnapshot -h ".$vc." -u ".$adminuser." -p ".$password." -f moref:".$vmidv." ".$namev." \| grep snapshot";

print " --->\[".$namev."]: Searching/Deleting stale snapshots";

my $result = `$cmd`;

($key, my $ssid) = split(/:/,$result);

chomp $key;

chomp $ssid;

my $trash = "";

if ($key eq "SsId") {

print "\n --->Deleting snapshot\[".$ssid."]\n";

$cmd = "ssh ".$esxhost." /usr/sbin/vcbSnapshot -h ".$vc." -u ".$adminuser." -p ".$password." -d moref:".$vmidv." ssid:".$ssid;

$trash = `$cmd`;

} else {

print "\n --->No snapshots found\n";

}

print " --->\[".$namev."]: Snapshot Creation Process\n";

print " --->Rotating snapshots on filer\[".$filer."]\n";

$cmd = "ssh ".$filer." snap delete ".$namev." daily.5";

print " --->".$cmd."\n";

$trash = `$cmd`;

  1. $i determines how many snapshots are in the rotation. The default here is 5

  1. Rotate snapshots

for(my $i = 5; $i >= 1; $i--) {

$cmd = "ssh ".$filer." snap rename ".$namev." daily.".($i -1)." daily.".$i;

print " --->".$cmd."\n";

$trash = `$cmd`;

}

print " --->Creating VCB Snapshot for \[".$namev."]\n";

$cmd = "ssh ".$esxhost." /usr/sbin/vcbSnapshot -h ".$vc." -u ".$adminuser." -p ".$password." -c moref:".$vmidv." ".$namev;

$trash = `$cmd`;

print " --->Creating snapshot daily.0 on filer \[".$filer."]\n";

$cmd = "ssh ".$filer." snap create ".$namev." daily.0";

$trash = `$cmd`;

$cmd = "ssh ".$esxhost." /usr/sbin/vcbSnapshot -h ".$vc." -u ".$adminuser." -p ".$password." -f moref:".$vmidv." ".$namev." \| grep snapshot";

$result = `$cmd`;

($key, $ssid) = split(/:/,$result);

chomp $key;

chomp $ssid;

print " --->Deleting VCB Snapshot\[".$ssid."]for VM\[".$namev."]\n";

$cmd = "ssh ".$esxhost." /usr/sbin/vcbSnapshot -h ".$vc." -u ".$adminuser." -p ".$password." -d moref:".$vmidv." ssid:".$ssid;

$trash = `$cmd`;

print "Done\n"

}

$counter ++;

}

Util::disconnect();

print "\n\n";

Reply
0 Kudos
0 Replies