The following somewhat crude perl from a backup script I wrote does what you want: (logging code removed) Hope this helps, it has worked for us for years.
Graydon Dodson grdodson@lexmark.com
--------------------------------------------------------------------- sub Snap_Create { my $netapp = shift; my $snapname = shift; my @volumes = @_;
my $vol; my $rc = 1; #true
foreach $vol (@volumes) {
my $cmd = "$rsh $netapp snap create $vol $snapname 2>&1";
## Try to create Snap my $response = `$cmd`;
## Delete & try again if already exists if ($response =~ /^\s*Snapshot already exists.$/m) { ## Delete existing snap and try again &Snap_Delete($netapp, $snapname, $vol);
$response = `$cmd`;
unless ($response =~ /^\s*creating\s+snapshot(.)*$/m) { $rc = 0; &Error("Unable to create snap "$snapname" on $netapp:$vol "); } next; }
## Were we successfull the first time? unless ($response =~ /^\s*creating\s+snapshot(.)*$/m) { $rc = 0; &Error("Unable to create snap "$snapname" on $netapp:$vol "); } } # foreach vol return($rc); }
sub Snap_Delete { my $netapp = shift; my $snapname = shift; my @volumes = @_;
my $vol; my $rc = 1; #true
foreach $vol (@volumes) {
my $cmd = "$rsh $netapp snap delete $vol $snapname 2>&1";
## Try to remove Snap my $response = `$cmd`;
unless ($response =~ /^\s*deleting\s+snapshot(.)*$/m) { $rc = 0; &Warning("Unable to remove snap "$snapname" on $netapp:$vol "); } } return ($rc); }