Export (0) Print
Expand All

Sample Scripts for Backing Up and Restoring the VMM Database

You can experiment with the Windows PowerShell scripts in this topic to learn how to back up and restore the Virtual Machine Manager database. The scripts differ depending on where the database is stored:

  • Locally. On the Virtual Machine Manager server itself (if the server is running either Microsoft SQL Server 2005 Express Edition SP1 or Microsoft SQL Server 2005)
  • Remotely. On a remote server running SQL Server 2005
Note
These scripts back up and restore the Virtual Machine Manager database. If you want to back up and restore the Virtual Machine Manager server itself (or a server functioning as a virtual machine host or as a library server), use your standard server backup procedure.

Backup/Recover: What You Need to Know Before You Start

It is possible that the SQL Server service (either SQL Server 2005 Express Edition SP1 or SQL Server 2005) is installed on the Virtual Machine Manager server but is not used to store the Virtual Machine Manager database. If you do not know whether the Virtual Machine Manager database is stored locally or on a remote server running SQL Server 2005, use the following procedure.

To determine whether the VMM database is stored locally or remotely
  1. Open the Registry Editor.

  2. Navigate to the following subkey:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft System Center Virtual Machine Manager 2007 Server\Settings\Sql

  3. View the value for OnRemoteServer:

    • If OnRemoteServer is set to 0, the database is on the local Virtual Machine Manager server.
    • If OnRemoteServer is set to 1, the database is on a remote server running the SQL Server service.

BackupLocalVMM.ps1

You can use the BackupLocalVMM.ps1 script to back up the Virtual Machine Manager database if the database is stored locally on the Virtual Machine Manager server.

How BackupLocalVMM.ps1 Works

The first command in the script connects to VMMServer1 in the Contoso.com domain, retrieves the server object from the Virtual Machine Manager database, and stores the server object in variable $VMMServer:

$VMMServer = Get-VMMServer -ComputerName "VMMServer1.Contoso.com"

The second command in the script uses the Backup-VMMServer cmdlet to back up the Virtual Machine Manager database stored on VMMServer1 to C:\VMMBackups on VMMServer1:

Backup-VMMServer –Path "C:\VMMBackups" -VMMServer $VMMServer

The destination path (C:\VMMBackups in the following example) must be on a server that stores the Virtual Machine Manager database. The server must be running SQL Server 2005 or SQL Server 2005 Express Edition SP1. The following example assumes that SQL Server is installed on VMMServer1 rather than on a remote server.

BackupLocalVMM.ps1 - Complete Script

Copy the following complete version of BackupLocalVMM.ps1 into a Notepad file, and save it as BackupLocalVMM.ps1.

# Filename:    BackupLocalVMM.ps1
# Description: Backs up the VMM database when the database 
#              is stored locally on the VMM server.

# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This 
# script is made available to you without any express, implied or 
# statutory warranty, not even the implied warranty of 
# merchantability or fitness for a particular purpose, or the 
# warranty of title or non-infringement. The entire risk of the 
# use or the results from the use of this script remains with you.

# Substitute the name of your VMM server and domain in this command:
$VMMServer = Get-VMMServer -ComputerName "VMMServer1.Contoso.com"

# Substitute your backup folder path and name for C:\VMMBackups:
Backup-VMMServer –Path "C:\VMMBackups" -VMMServer $VMMServer

BackupRemoteVMM.ps1

You can use the BackupRemoteVMM.ps1 script to back up the Virtual Machine Manager database if the database is stored on a remote server that is running SQL Server 2005.

How BackupRemoteVMM.ps1 Works

The first command in the script connects to VMMServer1 in the Contoso.com domain, retrieves the server object from the Virtual Machine Manager database, and stores the server object in variable $VMMServer:

$VMMServer = Get-VMMServer -ComputerName "VMMServer1.Contoso.com"

The second command in the script uses a network share (instead of a local folder as in BackupLocalVMM.ps1 example script) as the destination path. The command backs up the Virtual Machine Manager database that is stored on SQLServer01 to the VMMBackups share on SQLServer01:

Backup-VMMServer –Path "\\SQLServer01\VMMBackups" -VMMServer $VMMServer

The destination path (\\SQLServer01\VMMBackups in the following example) must be on a server that stores the Virtual Machine Manager database and is running SQL Server 2005. The following example assumes that SQL Server 2005 is installed on a remote server, called SQLServer01, that stores the Virtual Machine Manager database managed by VMMServer1.

BackupRemoteVMM.ps1 - Complete Script

Copy the following complete version of BackupRemoteVMM.ps1 into a Notepad file, and save it as BackupRemoteVMM.ps1.

# Filename:    BackupRemoteVMM.ps1
# Description: Backs up the VMM database when the database 
#              is stored on a remote SQL Server.

# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This 
# script is made available to you without any express, implied or 
# statutory warranty, not even the implied warranty of 
# merchantability or fitness for a particular purpose, or the 
# warranty of title or non-infringement. The entire risk of the 
# use or the results from the use of this script remains with you.

# Substitute the name of your VMM server and domain in this command:
$VMMServer = Get-VMMServer -ComputerName "VMMServer1.Contoso.com"

# Substitute your backup folder path and name for 
# \\SQLServer01\VMMBackups in this command:
Backup-VMMServer –Path "\\SQLServer01\VMMBackups" -VMMServer $VMMServer

RestoreLocalVMM.ps1

To restore the Virtual Machine Manager database after it was backed up locally, you must use the SCVMMRecover.exe command that is installed with Virtual Machine Manager. SCVMMRecover.exe is not a Windows PowerShell cmdlet.

How RestoreLocalVMM.ps1 Works

The following example script assumes that:

  • SCVMMRecover.exe is located in the default location for Virtual Machine Manager at C:\Program Files\Microsoft System Center Virtual Machine Manager 2007\bin\. The folder to which the database was backed up is the same folder (C:\VMMBackups) that is used in the BackupLocalVMM.ps1 example script.
  • The backup file name is VirtualManagerDB-07022007-233717.bak.

You must run SCVMMRecover.exe locally on the Virtual Machine Manager server to which you want to restore the database:

& 'C:\Program Files\Microsoft System Center Virtual Machine Manager 2007\bin\SCVMMRecover.exe' -Path 'C:\VMMBackups\VirtualManagerDB-07022007-233717.bak'

When you see the message "SCVMMRecover will replace the existing Virtual Machine Manager database with the backed up database. Do you want to continue?," type Y and then press ENTER to restore the Virtual Machine Manager database. If the operation is completed successfully, the message "VMM database recovery completed" appears.

RestoreLocalVMM.ps1 - Complete Script

Copy the following complete version of RestoreLocalVMM.ps1 into a Notepad file and save it as RestoreLocalVMM.ps1.

# Filename:    RestoreLocalVMM.ps1
# Description: Restores the Virtual Machine Manager database backed up 
#              locally by using the Backup-VMMServer cmdlet.

# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This 
# script is made available to you without any express, implied or 
# statutory warranty, not even the implied warranty of 
# merchantability or fitness for a particular purpose, or the 
# warranty of title or non-infringement. The entire risk of the 
# use or the results from the use of this script remains with you.

# This example script assumes that SCVMMRecover.exe is located in the 
# default location for Virtual Machine Manager at:
# C:\Program Files\
# Microsoft System Center Virtual Machine Manager 2007\bin\

# Substitute your backup folder and path for C:\VMMBackups, and 
# substitute the actual backup file name for 
# VirtualManagerDB-07022007-233717.bak
& 'C:\Program Files\Microsoft System Center Virtual Machine Manager 2007\bin\SCVMMRecover.exe' -Path 'C:\VMMBackups\VirtualManagerDB-07022007-233717.bak'

RestoreRemoteVMM.ps1

To restore the Virtual Machine Manager database after it was backed up remotely, you must use the SCVMMRecover.exe command that is installed with Virtual Machine Manager. SCVMMRecover.exe is not a Windows PowerShell cmdlet.

How RestoreRemoteVMM.ps1 Works

The following example script assumes that:

  • SCVMMRecover.exe is located in the default location for Virtual Machine Manager at C:\Program Files\Microsoft System Center Virtual Machine Manager 2007\bin\.
  • The remote share to which the database was backed up is the same share (\\SQLServer01\VMMBackups) that is used in the BackupRemoteVMM.ps1 example script.
  • The backup file name is VirtualManagerDB-07022007-233718.bak.

You must run SCVMMRecover.exe locally on the Virtual Machine Manager server to which you want to restore the database:

& 'C:\Program Files\Microsoft System Center Virtual Machine Manager 2007\bin\SCVMMRecover.exe' -Path "\\SQLServer01\VMMBackups\VirtualManagerDB-07022007-233718.bak"

When you see the message "SCVMMRecover will replace the existing Virtual Machine Manager database with the backed up database. Do you want to continue?," type Y and then press ENTER to restore the Virtual Machine Manager database. If the operation is completed successfully, the message "VMM database recovery completed" appears.

RestoreRemoteVMM.ps1 - Complete Script

Copy the following complete version of RestoreRemoteVMM.ps1 into a Notepad file, and save it as RestoreRemoteVMM.ps1.

# Filename:    RestoreRemoteVMM.ps1
# Description: Restores the Virtual Machine Manager database that was 
# backed up (on the remote SQL Server on which the database resides) 
# by using the Backup-VMMServer cmdlet.

# DISCLAIMER:
# Copyright (c) Microsoft Corporation. All rights reserved. This 
# script is made available to you without any express, implied or 
# statutory warranty, not even the implied warranty of 
# merchantability or fitness for a particular purpose, or the 
# warranty of title or non-infringement. The entire risk of the 
# use or the results from the use of this script remains with you.

# This example script assumes that SCVMMRecover.exe is located in the 
# default location for Virtual Machine Manager at:
# C:\Program Files\
# Microsoft System Center Virtual Machine Manager 2007\bin\

# Substitute your backup folder path and name for 
# \\SQLServer01\VMMBackups
# and substitute the actual backup file name 
# for VirtualManagerDB-07022007-233718.bak

& 'C:\Program Files\Microsoft System Center Virtual Machine Manager 2007\bin\SCVMMRecover.exe' -Path "\\SQLServer01\VMMBackups\VirtualManagerDB-07022007-233718.bak"
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft