Solved

Virtual Server 2005 R2 does not restart from Saved state after backup

Posted on 2008-06-23
2
797 Views
Last Modified: 2010-04-21
I have MS Virtual Server 2005 R2 running on Windows Server 2003 R2 Enterprise 32bit with several instances of VM servers. When a backup of the host server takes place, one or more of the virtual servers will  go into a saved state and not start backup. Is there a script to check the state of a virtual server/device and restart it from this saved state? It appears some what to be ramdom on what instance does not start backup.
0
Comment
Question by:mstraley
2 Comments
 
LVL 2

Accepted Solution

by:
Kelv1979 earned 500 total points
ID: 21864478
Hi

Credit for this belongs to David Wang really who produced the script i use for compacting my VHDs, check out the full script at http://blogs.msdn.com/david.wang/archive/2006/04/17/HOWTO-Perform-VHD-Maintenance-Automatically.aspx

However, if you just want to check the state and then start up the VHD the bit you need is below. Save it as a .js file and call it from the command prompt using cscript filename.js

Hope this helps


var ERROR_FILE_NOT_FOUND    = 2;
var ERROR_INVALID_PARAMETER = 87;
 
var GUEST_OS_SLEEP_RESOLUTION = 5000;
var CLEAR_LINE = String.fromCharCode( 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 );
var CRLF = "\r\n";
 
var VM_STATE_OFF            = 1;
var VM_STATE_SAVED          = 2;
var VM_STATE_RUNNING        = 5;
var VM_STATE_PAUSED         = 6;
 
var strServer               = "SERVER_NAME";
var strVMName               = "VM_NAME";
 
var Fso     = new ActiveXObject( "Scripting.FileSystemObject" );
var objVS   = new ActiveXObject( "VirtualServer.Application", strServer );
var objVM   = objVS.FindVirtualMachine( strVMName );
var task;
 
//
// Locate the named Virtual Machine
// If it is not found, bail.
//
if ( null == objVM )
{
    LogEcho( "Virtual Machine " + "\"" + strVMName + "\"" + " was not found on server " + strServer );
    Quit( ERROR_FILE_NOT_FOUND );
}
 
LogEcho( "Selected Virtual Machine " + "\"" + strVMName + "\"" + " on server " + strServer );
 
//
// Virtual Machine is not running. Start/resume it
//
 
if ( objVM.State != VM_STATE_RUNNING )
{
    LogEcho( "VM is NOT already running." );
 
    if ( objVM.State == VM_STATE_OFF ||
         objVM.State == VM_STATE_SAVED )
    {
        LogEcho( "Starting VM..." );
        task = objVM.Startup();
        WaitForTask( task );
    }
    else if ( objVM.State == VM_STATE_PAUSED )
    {
        LogEcho( "Resuming VM..." );
        task = objVM.Resume();
    }
    else
    {
        LogEcho( "Unexpected VM State: " + objVM.State );
        Quit( ERROR_INVALID_PARAMETER );
    }
}
else
{
    LogEcho( "VM is already running." );
}
 
function Quit( errorNumber )
{
    WScript.Quit( errorNumber );
}
 
function LogEcho( str )
{
    WScript.Echo( str );
}
 
function FormatErrorString( e )
{
    return e.number + ": " + e.description;
}
 
function WaitForTask( task )
{
    var complete;
    var strLine = "";
    var cchLine = 0;
 
    while ( (complete = task.PercentCompleted) <= 100 )
    {
        strLine = CLEAR_LINE.substring( 0, cchLine ) + complete + "%   ";
        cchLine = strLine.length;     //this should not exceed CLEAR_LINE
 
        WScript.Stdout.Write( strLine );
 
        if ( complete >= 100 )
        {
            // Delete the % display so that next line is clean.
            WScript.Stdout.Write( CLEAR_LINE );
            break;
        }
 
        WScript.Sleep( GUEST_OS_SLEEP_RESOLUTION );
    }
}

Open in new window

0
 

Author Closing Comment

by:mstraley
ID: 31469728
I believe this is what I was looking for, thank you for your help.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Scheduling replication Hyper-v 8 628
SCVMM 2012 error 2940 6 63
Best Practices for Backup of a Linux (Ubuntu) Server Running VMWare 3 96
Sizing up a Hyper-V server 10 102
As the most of you know, Hyper-V does not support usb redirection. But with some relative easy steps we can redirect our usb disk to a Hyper-V virtual machine. First on your Hyper-V Server host open Server Manager and select Disk Management …
Every once-in-a-while, when you try to add a XenServer host to the System Center Virtual Machine Manager console, it will generate a certificate error, and the XenServer host will not be added to Virtual Machine Manager: If you are experiencing t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question