VMware Cloud Community
wildcattdw
Contributor
Contributor
Jump to solution

Finding snapshots

Good day all!

I would like to know if there is any easy way to find snapshots on guests.

I have found the odd occurance of ESXRanger either failing during back up, therefore not removing the snapshot, or not successfully removing the snapshop (for whatever reason.) Also, I'll be requested to take a snapshot prior to a patch to a guest OS, or software upgrade, and after several days, I tend to forget all about it.

SO, back to the question, how do I best find these snapshots, short of going guest by guest? Any help is appreciated!!!

Reply
0 Kudos
1 Solution

Accepted Solutions
kix1979
Immortal
Immortal
Jump to solution

At a minimum I just do a find on *delta.vmdk. From that I can manually look, I don't have a pretty script yet, I'm still learning lots of shell scripts.

Thomas H. Bryant III

View solution in original post

Reply
0 Kudos
22 Replies
kix1979
Immortal
Immortal
Jump to solution

Actually, our next release should resolve most of these issues, but in the mean time you can either look on the host/VC for the snapshots, but sometimes esxRanger or not, they will not commit and return a false positive to the client. At that point you have to look on the console for the \*delta* files.

Thomas H. Bryant III
hicksj
Virtuoso
Virtuoso
Jump to solution

I have a perl script that I use that lists out all the vmdk files, and highlights any that are snapshots. Being that all my hosts can see all LUNs, it need only be run in one location.

Relevant chunks of code:

#get a list of all volumes on the host

@vmfs_list = `vdf -Ph`;

foreach $line (@vmfs_list) {

chomp ($line);

if ($line =~ /^(\/vmfs\/volumes.*)/) {

@details = split(/\s+/, $line);

$details[5] =~ /\/(.)\/(.)\/(.*)/;

$volume = $3;

...do something to print out volume info if you wish...

#list all the files in each directory

@file_list = `ls -Rsh1 $details[5]/`;

foreach $entry (@file_list) {

chomp ($entry);

...check the different entry types...

#i.e. if its a delta file:

if ($entry =~ /(\S+) (.*-delta\.vmdk)/) {

...print stuff...

}

}

}

}

Message was edited by:

hicksj

There are most likely more elegant ways to do this... you could list out all directories and pull out snapshot info much simpler, but my script does a lot more with the info pulled in.

admin
Immortal
Immortal
Jump to solution

Kix, I've noticed these false positives too, can you share the workaround for picking them up?

Reply
0 Kudos
wildcattdw
Contributor
Contributor
Jump to solution

I'll have to take a look at your code. I am not much of a perl scripter (I can bash, but not perl) and see what I can come up with, thanks.

Reply
0 Kudos
kix1979
Immortal
Immortal
Jump to solution

At a minimum I just do a find on *delta.vmdk. From that I can manually look, I don't have a pretty script yet, I'm still learning lots of shell scripts.

Thomas H. Bryant III
Reply
0 Kudos
bjd145-1
Enthusiast
Enthusiast
Jump to solution

This script will query VirtualCenter and list all Virtual Machines that have a snapshot. Its based the VI3 Perl ToolKit (http://sourceforge.net/projects/viperltoolkit)

#!/usr/bin/perl -w

use strict;

use warnings;

use Getopt::Long;

use VMware::VIRuntime;

my %opts = (server => undef,

userid => undef,

password => undef);

GetOptions (\%opts,

"server=s",

"userid=s",

"password=s");

if( !defined ($opts\{server} && $opts\{userid} && $opts\{password}) ) {

help();

exit (1);

}

\# login

my $url = "https://" . $opts\{server}. "/sdk/vimService";

Vim::login(service_url => $url, user_name => $opts\{userid}, password => $opts\{password});

\# get VirtualMachine views for all powered on VM's

#my $vm_views = Vim::find_entity_views(view_type => 'VirtualMachine');

\# snapshot each VM

my $i;

foreach (@$vm_views) {

if( defined $_->snapshot ) {

print "----


\n";

print $_->name . " has at least one snapshot defined . . . \n";

foreach $i (0 .. $#\{$_->snapshot->rootSnapshotList} ) {

print "\t" . $_->snapshot->rootSnapshotList->\[$i]->name . " @ " . $_->snapshot->rootSnapshotList->\[$i]->createTime . "\n";

}

print "----


\n";

}

}

\# logout

Vim::logout();

sub help {

my $help_text =

Example:

query_snapshot.pl --server dr-vc1 --userid administrator --password mypassword

END

print $help_text;

}

Reply
0 Kudos
kix1979
Immortal
Immortal
Jump to solution

The problem is that Virtual Center has a bad habit of reporting that the snapshots have been committed when they actually have not been.

Thomas H. Bryant III
Reply
0 Kudos
bretti
Expert
Expert
Jump to solution

I actually prefer this method. "find on delta.vmdk" It's quick and easy.

2cents

Reply
0 Kudos
bjd145-1
Enthusiast
Enthusiast
Jump to solution

I haven't read anything about that. So far the script hasn't failed me, but I'll keep an eye on any existing delta vmdk. Thanks

Reply
0 Kudos
wildcattdw
Contributor
Contributor
Jump to solution

LOTS of good stuff everyone! I love collaberation.

OK, so here is what I have come up with...

Whipped together the following scripts; they are still works in progress, so don't judge to harshly. I do have RSA keypairs set up between the machine that I run all my scripts from and all my ESX hosts, so the logins are not interactive.

snapreport[/b]

#!/bin/bash

#

#

#

#

\# Let's start off by setting the 'server1' variable to a name that isn't valid

server1=defaultserver

\# I like to offer the user some information about what they are doing

echo "This script will check for the presence of snapshots on SAN volumes."

echo "This will take a few moments, please be patient."

\# OK, now we will actually do something. Let's call the 'snapcheck' script and put the output in a file to be manipulated.

./snapcheck > snapcheckoutput

\# The output of the above step is pretty ugly, and contains plenty of extra information, we are only interested in the server name. Let's do something about this.

cat snapcheckoutput | grep vmfs | awk -F / '\{print $5}' > snapshotstmp1

\# Since the 'snapcheck' script runs on multiple machines, and some share common SAN volumes, as well as the fact that a server with more than one vmdk file will result in multiple entries, we'll now work on making a list with a single entry for each server.

#Sort the (somewhat) cleaned up file; we want multiple entries of a single server name to show up next to each other.

sort snapshotstmp1 > snapshotstmp2

\# Clean out the file that contains the final product.

cat /dev/null > snapshots

\# I love loops. This one compare each line to the previous, only passing the server name to the final report file when they are different.

for server in `cat snapshotstmp2`

do

server2=$server

if \[ $server1 != $server2 ]

then

echo $server2 >> snapshots

server1=$server2

fi

server1=$server2

done

\# Clean up temporary files, yo.

rm -f snapshotstmp1

rm -f snapshotstmp2

rm -f snapcheckoutput

\# Offer the server list to the user...

cat snapshots

\# ... and let them know they can look at the report any time down the road.

echo "You can view these results later by looking at the \"snapshots\" file"

exit 0

snapcheck[/b]

#!/bin/bash

#

#

#

\# This script runs through our universal servers file and looks for the existence of 'delta' files. This script is called by other scripts.

for server in `cat servers`

do

echo "Checking for the presence of snapshots on $server"

ssh $server "find /vmfs/volumes/ -name '*delta.vmdk'"

done

exit 0

I put plenty of comments in the scripts. If anyone has any questions, I'd be happy to elaborate.

Tim

Reply
0 Kudos
arnoldvp
Contributor
Contributor
Jump to solution

Issue the following command from the root folder (cd /) of an ESX host:

ll -R | grep "vmsn"

Reply
0 Kudos
CaryBarker
Contributor
Contributor
Jump to solution

very short and elegant solution; thanks Arnoldvp!

BTW - I'm having the same problems with esxRanger. I just upgraded to the latest version and the problem -seems- to have gone away. I'm going to use this command to do a quick check every morning just to make sure.

Reply
0 Kudos
JKevinezz
Contributor
Contributor
Jump to solution

Team,

I have found an additional command. I know grep is a powerful tool so I am sure someone can improve on this.

1. cd /vmfs/volumes

2. ls * -R -s -h | grep "delta.vmdk" or ls * -R -s -h | grep "vmsn"

3. ls * -R -s -h | egrep 'vmsn|delta.vmdk'

If you want information all together:

Hope this helps!! I would think the next step is to output it into a file that can be downloaded or even run as a cron job renaming the file to observe growth trend.

Reply
0 Kudos
hicksj
Virtuoso
Virtuoso
Jump to solution

A problem with snap_hunter is that it must execute on a ESX host. Since my own original followup on this thread, I've long ago switched my scripts to use VI Perl Toolkit, very similar to the one that was posted in this thread, setup to generate weekly email reports. With the COS going away (at least in one ESX thread), I recommend not proliferating non-api based scripts. IMHO, the most useful scripts going forward will be those not based on having a console OS around.

Reply
0 Kudos
dinny
Expert
Expert
Jump to solution

Hiya,

I do totally agree with the concept of using the perl toolkit in preference to the COS etc.

The script listed further up the thread also seemed to use data directly off the ESX server though?

I would prefer to use the API etc for snapshots - but as far as snapshot info goes it doesn't seem to offer all the functionality that it could at the moment?

I've found some of the info in the VC base can definitely be incorrect.

That's why in this particular case I prefer something that does directly read the info from the .vmsd snapshot file(s) on the LUNs

Are you happy that you always get just as accurate snapshot info from the perl toolkit version as from the info in the .vmsd file?

If so - do you mind me asking what snapshot properties you look at / view with the toolkit?

Dinny

Reply
0 Kudos
dwchan
Enthusiast
Enthusiast
Jump to solution

I am not sure if i am doing something wrong or reach the limitation of the software. I have install SnapHunter on one of my local ESX 3.0 server and it works great. It detect my snap, etc, without issue.

However, can snap hunter works with Virtual center also, or able to query a remote esx server from another esx server? I would be great if i can just install a single copy of the perl script and run it from a single box, versus install multiple copy.

If it can, what is the proper syntax? I try

snaphunter.pl -h hostname -u username -p password without success

if you are talkint to the virtual center, what do you use for username? do you use -u username or -u domain\username?

Reply
0 Kudos
dinny
Expert
Expert
Jump to solution

Hiya,

Snaphunter will not work via VC.

It relies on the ESX server's direct connections to the vmfs volumes.

However if your ESX servers all share the same LUNs (as they often will, for vmotion etc) - then it only needs to be installed on one of the ESX servers.

I recently added some updates to Alex's version of snaphunter - but I've not heard back from him as yet - if you pm me or give me your email address I could mail you a copy of the amended version for you to check out if you like?

Dinny

Reply
0 Kudos
dwchan
Enthusiast
Enthusiast
Jump to solution

My email is and would love to take a look at your mod script. You did mention that snap hunter doesn't work with VC, but can snap hunter install on server1 query the snap on server2 (note: server 1 and 2 are in the same cluster)

dwc

Reply
0 Kudos