VMware Cloud Community
zemotard
Hot Shot
Hot Shot

How to launch a script automaticly before a snapshot

Hi everybody, could you tell me how to launch a script automaticly (to close a database) before a snapshot.






Best Regards

Best Regards If this information is useful for you, please consider awarding points for "Correct" or "Helpful".
0 Kudos
6 Replies
admin
Immortal
Immortal

You'll need to launch it via a guest OS level script, WMI if you're using Windows. I'd say the best approach would be to use either the VI Perl Toolkit or Powershell API to initiate the snapshot, in the script write a WMI trigger to quiesce the database before it does the snap.

0 Kudos
zemotard
Hot Shot
Hot Shot

What's WMI ?

Do you have an script example ?


Best Regards

Best Regards If this information is useful for you, please consider awarding points for "Correct" or "Helpful".
0 Kudos
admin
Immortal
Immortal

Sorry I haven't got any examples to show you, best off having a google and reading the MS reference/samples on WMI (Windows Management Interface).

http://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx

http://msdn.microsoft.com/en-us/library/aa394585(VS.85).aspx

http://msdn.microsoft.com/en-us/library/aa561208.aspx

You could either stop the SQL service, or if you're running Windows 2003 using the Volume Shadow Copy Service to Quiesce the DB, more complicated to script but a nicer solution as the DB can remain live and still give a consistent state snapshot.

Hope this helps.

Alex

zemotard
Hot Shot
Hot Shot

Nobody has an example for me ?

Best Regards If this information is useful for you, please consider awarding points for "Correct" or "Helpful".
0 Kudos
Draconis
Enthusiast
Enthusiast

Here are your options (). That has the Windows Services Snap-in approach and the command line net stop approach which you can place inside a batch file and schedule to run prior to a snapshot.

This is a sample of stopping a service through WMI (). The only thing you have to take note is that you dont want the changestartmode line since that will disable the service. Copy and paste the whole script into notepad, save it as a .vbs file, and it should look something like so:

NOTE: Scripts are provided AS IS. Please be aware that YOU MUST TEST this script or any script in a test environment prior to performing such tasks in a production environment. I am not a DBA and will not be able to account for all catch-22s when it comes to stopping a service for a database such as SQL Server.

strComputer = "."

Set objWMIService = GetObject("winmgmts:
" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery("Select * from Win32_Service where Name = 'MSSQLSERVER'")

For Each objService in colServiceList

If objService.State = "Running" Then

objService.StopService()

Wscript.Sleep 5000

End If

Next

The strComputer set to "." tells the script to bind to the local computer where the script is run. You will have to provide the hostname or better yet, the IP address instead.strComputer="sql-01" or strComputer="192.168.xxx.xxx"

If you have found my answer helpful or correct, please consider awarding points.
0 Kudos
zemotard
Hot Shot
Hot Shot

Else, is it possible to launch the snapshot request from my vm to esx server using ssh connection ?

If this information is useful for you, please consider awarding points for "Correct" or "Helpful".

Best Regards If this information is useful for you, please consider awarding points for "Correct" or "Helpful".
0 Kudos