VMware Cloud Community
admin
Immortal
Immortal

Announcement: New Utility released - Snapshot Hunter

Hi Guys,

I've written a free utility, Snap Hunter, to search all VMFS volumes viewable by a host and email a report of which VMs have snapshots, how many layers deep the snap is on each VMDK, when it was created and how large the delta's are. It also reports current snaphot name and SsId and includes a menu driven schedule configurator.

http://www.xtravirt.com/index.php?option=com_remository&Itemid=75&func=fileinfo&id=19

Comments suggestions welcome. Hope it's useful.

Cheers,

Alex

0 Kudos
16 Replies
Chris_S_UK
Expert
Expert

Nice one Alex.

It seems to work ok on the 1 host I have tried it on so far (and that includes testing the email bit)...with one exception: when I try to run it against a different host using the -h parameter, it seems to report on the local host and not the one specified.

Chris

0 Kudos
dkfbp
Expert
Expert

Is this script only for esx3 servers? I have a lot of esx 2.5 servers where I need to check for .redo files. Is the script able to do that?

Best regards Frank Brix Pedersen blog: http://www.vfrank.org
0 Kudos
admin
Immortal
Immortal

If your hosts are clustered you should only need to run it on one host - it scans all VMFS volume that a host can see.

The -h parameter is only used for retrieving SsId and automatically removing snapshots (currently an experimental feature), you can currently only point the script at the host running the script or a VC server. Pointing it at a VC server is the preferred method, but like I said, the -h switch isn't needed for reporting VM snaps so just leave it off if you're having problems with it.

0 Kudos
admin
Immortal
Immortal

The script is for ESX3 only I'm afraid.

0 Kudos
beckmana
Enthusiast
Enthusiast

Hi,

i think it is easyer to select the vcenter database

select dns_name, snapshot_name, create_time

from vpx_snapshot,vpx_vm

where vpx_vm.id = vpx_snapshot.vm_id

Andreas

0 Kudos
admin
Immortal
Immortal

Does that give you the size of each delta? I also wanted something that I could set up and forget about, that would just email me a report daily.

0 Kudos
beckmana
Enthusiast
Enthusiast

Hi,

i use the following script from vcenter server to search for snapshots and send it via email.

#!/usr/local/bin/perl

#

\#

#

require "ctime.pl";

require "flush.pl";

use DBI;

use Net::SMTP;

use Time::Local;

use File::Path;

\# Globale Variablen

#

use vars qw/ %opt /;

&declareGlobalVariables;

$dbh = &getOracleLogin("$ORACLE_SID", "$ORACLE_USERID", "$ORACLE_PASSWORD");

$dbh->\{LongReadLen} = 64000;

&checkSnapshot;

&logoffOracle($dbh);

exit;

\# \+----


+

\# | SUB ROUTINES |

\# \+----


+

sub declareGlobalVariables {

$ORACLE_SID = "";

$ENV\{'ORACLE_SID'} = "$ORACLE_SID";

$ENV\{'ORACLE_HOME'} = "D:
oracle
product
10.2.0
client_1"; # pracle client path

$MAILSERVER = "data();

  1. Send the header.

$smtp->datasend("Subject: Snapshot $status\n\n");

  1. Send the body.

$smtp->datasend("$message\n");

$smtp->datasend("$status\n");

$smtp->dataend();

$smtp->quit;

}

#

\# checkSnapshot

#

sub checkSnapshot {

$sql_statement="select dns_name, snapshot_name, create_time , floor((((sysdate - create_time)2460*60)/3600)-2 ) age from vpx_snapshot,vpx_vm where vpx_vm.id = vpx_snapshot.vm_id";

\# print STDERR "SQL $sql_statement" ;

unless ($snap_cursor = $dbh->prepare("$sql_statement")) {

&programMessage("Could not prepare SELECT_SNAPSHOT cursor", "$sql_statement $DBI::errstr" );

$dbh->rollback;

&logoffOracle($dbh);

exit;

}

unless ($snap_cursor->execute) {

&programMessage("Could not execute SELECT_SNAPSHOT cursor", "$sql_statement $DBI::errstr" );

$dbh->rollback;

&logoffOracle($dbh);

exit;

}

$snap_cursor -> bind_columns(undef,\$dns_name,\$snapshot_name,\$create_time,\$age);

while($snap_cursor->fetch() ){

if( $age >= $SNAP_THRESHOLD ) {

print "Warning: Snapshot $dns_name $snapshot_name $create_time exists $age Stunden\n";

&programMessage("VCB snapshot exists : $dns_name $snapshot_name $create_time seit $age hours", "Snapshot exists $dns_name $snapshot_name $create_time" );

return 1;

}

}

unless ($snap_cursor->finish) {

&programMessage("Could not finish snap_cursor", "$sql_statement" );

$dbh->rollback;

&logoffOracle($dbh);

exit;

}

}

Andreas

0 Kudos
admin
Immortal
Immortal

Thanks for sharing. Unfortunately we don't use Oracle, we use MS SQL 2005. Also I've seen situations where the database information about snapshots is incorrect, which is part of the reason I wanted to check at the filesystem level, to see what was really going on with the VMDKs - the script I wrote reports independantly on every VMDK it finds.

0 Kudos
depping
Leadership
Leadership

tapping into the VC database is useless when a snapshot is orphaned.

I created a script about a week ago, which is a simplified version of this script and creates a html report. checks for snapshots and orphaned snapshots. and creates an html email with warning levels,

0 Kudos
davidbarclay
Virtuoso
Virtuoso

Anyone getting this warning

"Use of uninitialized value in string at ./snap_hunter.pl line 257."

It still works, just wondering.

Dave

0 Kudos
admin
Immortal
Immortal

Nope I don't get that, that's a line from the section of code that maps volume friendly name to VMFS UUID.

Do you have any odd characters in your volume names? I accounted for spaces and brackets, but maybe I've missed something...

0 Kudos
jparnell
Hot Shot
Hot Shot

Great - thanks. Just what i'm after.

I see it has the ability to display delta sizes. when i run the script it doesn't display this though. Any suggestions?

James

0 Kudos
admin
Immortal
Immortal

Hmm, interesting. Does it just show a blank line? It should automatically show delta sizes. Are you storing the deltas in a different directory to the VM config file?

0 Kudos
jparnell
Hot Shot
Hot Shot

It doesnt seem to output anything. Our delta files are stored with the VMs.

I've just done some playing around with the script, and it doesn't seem to enter this if statement:

if ($line =~ /.*\s\d\s\w\s\w\s(\w)\s\w\s\d\d\s\d\d:\d\d\s(\S\-000\[0-9]+)-delta\.vmdk$/) {

I don't know enough about perl to know what this all means though!

0 Kudos
admin
Immortal
Immortal

That's the line that grabs the name of the delta files for processing. Could you PM me some information about your VMDK and Delta naming (an ls -l of the VM directory) and VMFS volume name and I'll try and work out why it's failing?

Does this happen with all VMs or just one?

0 Kudos
dinny
Expert
Expert

Hiya,

I had a similar issue.

The problem was on that line - in my case it was because delta sizes of greater than 1GB were not catered for.

Alex has now posted an amended script on the xtravirt site

Dinny

0 Kudos