Backups are an important component to any disaster recovery plan, and the majority of people religiously backup their servers. Backing up the configuration of the hosts that run your virtual environment on the other hand is not so common, this may be because you can build and deploy a host in record time but it also relies on you knowing exactly how the host is/was configured.
Backing up a VMware host configuration is not something that many backup solution providers offer. The process is not difficult and VMware provide instructions that are quite straightforward KB2042141. You could regularly log in to each host, backup the configs and FTP them out to your file server and then back them up using your normal methods, but if you have quite a few hosts or don’t make changes that often then this will get overlooked and you will be left with out of date backups.
vSphere PowerCLI can be used to automate the backup process and along with a scheduled task on one of your servers, can regularly backup all hosts without any input from you.
vSphere Power CLI installation
You can grab vSphere PowerCLI from the VMware website. This post assumes that you’re installing it on a Windows Server 2008 R2 server. The installation is straightforward and once complete will give you a few extra items in the start menu, but more importantly it will give you the VMware.VimAutomation.Core PowerCLI cmdlets.
After the installation is complete, launch PowerCLI and execute the following command
This will change the policy of the server PowerShell environment to only run scripts downloaded from the internet if they have been signed by a trusted authority. If you wanted to you could use Unrestricted or Bypass to have no restrictions imposed. The script attached to this post is not signed so either type it out or copy and paste into a new text file that you’ve created on your server.
This script will connect to your vCenter, check/create a location to store the host backups and then retrieve the configs for each host. Here is a line-by-line breakdown:
- 1-11: Comments, information, Author and licensing
- 13: Load the PowerCLI cmdlets (Note: this needs to be done for when you schedule the script to run with PowerShell)
- 15: Enter the DNS name or IP address of your vCenter server
- 16: Enter a location for the backups to be stored
- 18: Makes the connection to the VC
- 21-24: Check to see if the backup location exists, if not then create it
- 26-29: Loop over all Hosts connected to the vCenter, backup and store the configuration in the location provided
Copy the script here…
# = PowerCLI script to automatically
# = backup all Hosts of a vCenter to a
# = network location
# = Author: Craig Soutar
# = Contact: email@example.com
# = License GPLv3 – http://www.gnu.org/licenses/gpl-3.0-standalone.html
# = Version: 0.2
# = Last Modified: 13/09/2013
$VC = “vcenter01”
$location = “\\fileserver01\host_backups”
if(-Not(Test-Path -PathType Container $location))
New-Item -ItemType Directory -Force -Path $location
foreach($hostsvr in Get-VMHost)
Get-VMHostFirmware -VMHost $hostsvr.name -BackupConfiguration -DestinationPath $location
Author: Craig Soutar
Craig handles the day-to-day requirements of our managed service customers with a focus on VMware, EqualLogic, Backup Solutions and Databases. Outside of work Craig spends the majority of his time programming and providing technical support for the Open Source Software community.