Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to automatically stop virtual machine in Virtual Server 2

Status
Not open for further replies.

terrassa5

IS-IT--Management
Feb 22, 2005
40
GB
I have a server virtualized using Virtual Server 2005. Host server has a LTO device and Veritas Backup Exec software with Remote Agents to do network backup of all other physical servers.

To do backup of virtualized server I have two posibilities:

- Do network backup using Veritas Backup Exec as we are doing actually with all other physical servers.

- Do local backup of files of virtual server, instead of backup of virtualized operating system.

First option will allow us to recover specific files, but second option is faster and I think it's safer in case of total recovery. This server only has one software and there is no user data nor databases, so there will not be changes usually. We prefer to use second option but in this way virtual machine must be stoped during backup.

I need to stop virtual machine automatically at a specific time and start it again after backup, but I don't know how to do it. Can anyone help me?
 
This is what I did for a project a while back..

I have 3 scheduled tasks.
1. 12AM Gracefully shutdown the VM's (VBscript)
2. 12:30AM Backup the .vhd and .vmc files (Native backup task)
3. 4:00AM Start the VM's (VBscript)

Save the code to .vbs file and have the tasks execute it

This will gracefully shut down all VM's
Code:
On Error Resume Next

Set objVS = CreateObject("VirtualServer.Application")
set colVMs = objVS.VirtualMachines

For Each objVM in colVMS
	If objVM.State = 5 then
		Set objGuestOS = objVM.GuestOS
		objGuestOS.Shutdown()
		msgbox "Shutting Down " & objVM.Name	
		set objGuestOS = nothing
	End If
Next

Set colVMs = nothing
Set objVS = nothing

Wscript.quit

This will start up all VM's.
Code:
On Error Resume Next

Set objVS = CreateObject("VirtualServer.Application")
set colVMs = objVS.VirtualMachines

For Each objVM in colVMS
	If objVM.State = 1 then
		objVM.Startup()
		msgbox "Starting up " & objVM.Name	
	End If
Next

Set colVMs = nothing
Set objVS = nothing

Wscript.quit





(yay! shameless advertising. my side business)
 
Thank you very much, your scripts work great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top