Backup & Restore ESXi Host Configuration (VMware PowerCLI)
DISCLAIMER: The information in this guide is provided "as is" without any guarantee of completeness, accuracy, timeliness, or of the results obtained from the use of this information. The author assumes no responsibility for any errors or omissions in the content. It is meant for general information purposes only and should not be used as a substitute for professional advice. The author is not responsible for any damages caused by the use of this information. By using this guide, you agree to hold the author harmless from any and all claims, damages, or expenses that may arise from your use of the information.
Requirements
- A Windows Machine (for PowerShell & Task Scheduler).
- Powershell v5.1+
- VMware PowerCLI.
- Ensure that the server that is running the Windows Task Scheduler has access to the backup path.
- Ensure that each ESXi host has a scratch location configured. This is done via ESXi Advanced settings . A reboot is required. See example below:
Key: ScratchConfig.ConfiguredScratchLocation Value: /vmfs/volumes/5e8f3cd3-c4d9f80c-bf9a-90e2ba3559c0/_scratch/deepblue1 Key: ScratchConfig.CurrentScratchLocation Value: /vmfs/volumes/5e8f3cd3-c4d9f80c-bf9a-90e2ba3559c0/_scratch/deepblue1NOTE: Remember, the above Key/Value pairs are only an example, replace the Value as needed. This will be different for each environment.
Scheduled Backup
Requirements
- A Windows Machine (for PowerShell & Task Scheduler).
- VMware PowerCLI.
- Ensure that the server that is running the Windows Task Scheduler has access to the backup path.
- Ensure that each VMware ESXi host has a scratch location configured. A reboot is required. See example below:
Key: ScratchConfig.ConfiguredScratchLocation Value: /vmfs/volumes/5e8f3cd3-c4d9f80c-bf9a-90e2ba3559c0/_scratch/deepblue1 Key: ScratchConfig.CurrentScratchLocation Value: /vmfs/volumes/5e8f3cd3-c4d9f80c-bf9a-90e2ba3559c0/_scratch/deepblue1NOTE: In the example above, replace
deepblue1with the respective VMware ESXi hostname.
PowerShell Script
Replace all <PLACEHOLDER> text with their respective values. (e.g., <PASSWORD> = YourPassword)
# Environment variables
$DateTime = (Get-Date -Format "yyyyMMdd_hhmmtt").ToString()
$BackupPath = "\\<ESXi_IP_Address>\VMware\Backup\ESXi\$DateTime"
$vCenterServer = "<vcsa1.local.lan>"
# Ignore certificate errors, unless using trusted certs in the environment
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
# Connect to the vCenter/ESXi Server
Connect-VIServer -Server $vCenterServer -User administrator@vsphere.local -Password <PASSWORD>
# Check if $BackupPath exists
if (!(Test-Path $BackupPath -PathType Container))
{
New-Item -ItemType Directory -Force -Path $BackupPath
}
# Enumerate all of the ESXi hosts and backup the configs to the $BackupPath
Get-VMHost | Get-VMHostFirmware -BackupConfiguration -DestinationPath $BackupPath
# Enumerate all of the ESXi hosts and record the Name, Version and Build in the Manifest file
Get-VMHost | Select Name,Version,Build | Sort Name | Out-File -FilePath $BackupPath\$("$DateTime" + '_Manifest.txt')
# Disconnect from the vCenter Server
disconnect-viserver * -confirm:$false
Windows Task Scheduler
Action: Start a program
Program/script: Powershell.exe
Add arguments (optional): -ExecutionPolicy Bypass -File "C:\Scripts\ESXi_Config_Backup.ps1"
Manual Backup
Outside of scheduled backups, manual backups are performed prior to any major environment changes to ESXi or the underlying hardware - such as replacing the ESXi boot device.
Requirements
- A Windows Machine (for PowerShell & Task Scheduler).
- VMware PowerCLI.
Backup Commands
Replace all <PLACEHOLDER> text with their respective values. (e.g., <PASSWORD> = YourPassword)
Connect-VIServer -Server deepblue1.local.lan -User root -Password <password>
Connect-VIServer -Server deepblue2.local.lan -User root -Password <password>
Connect-VIServer -Server deepblue3.local.lan -User root -Password <password>
Get-VMHostFirmware -vmhost deepblue1.local.lan -BackupConfiguration -DestinationPath C:\Users\sysadmin\Desktop\esxi_backups
Get-VMHostFirmware -vmhost deepblue2.local.lan -BackupConfiguration -DestinationPath C:\Users\sysadmin\Desktop\esxi_backups
Get-VMHostFirmware -vmhost deepblue3.local.lan -BackupConfiguration -DestinationPath C:\Users\sysadmin\Desktop\esxi_backups
NOTE: In the example above, replace deepblueX with the respective VMware ESXi hostname. The example represents three different hosts.
Manual Restore
Manual restores are performed to rollback ESXi to a previous configuration. They can also be used to restore prior configurations on new boot devices.
Requirements
- A Windows Machine (for PowerShell & Task Scheduler).
- VMware PowerCLI.
Restore Command
Replace all <PLACEHOLDER> text with their respective values. (e.g., <PASSWORD> = YourPassword)
Connect-VIServer -Server <ip> -User root -Password <password>
Set-VMHost -VMHost <ip> -State Maintenance
Set-VMHostFirmware -vmhost <ip> -Restore -SourcePath C:\Users\sysadmin\Desktop\esxi_backups\configBundle-deepblue1.local.lan.tgz -HostUser root -HostPassword <password>
Sources
- N/A
KB Change/Issue Log
yyyy/mm/dd - Title
Issue
N/A
Solution
N/A
KB Meta
| Page Includes | @9#bkmrk-callout-danger-NoResponsibilityDisclaimer-5wod5ufe |
| Page Includes | @9#bkmrk-callout-info-ReplaceAllPlaceholderText-86k2hi4r |



