自动执行 VMWare 配置备份

自动执行 VMWare 配置备份

我正在寻找一种方法来自动执行 VMWare ESXi 配置的夜间备份,以实现灾难恢复。

理想情况下,该脚本将连接到我的 vCenter 服务器,轮询主机,然后在逻辑目录结构中备份配置,包括当前正在运行的 ESXi 版本,因为配置备份只能恢复到运行完全相同版本的机器上。

是否有这样的脚本可用?

答案1

当然有。以下是使用 Power-CLI 的示例:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

$backupbasedir = "<Base directory to store the backups>"
$username = "<Username with the correct right in vCenter>"
$password = "<Password for that user>"
$VCenterServer = "<FQDN of the vCenter server>"

if ($backupbasedir.Substring($backupbasedir.Length - 1, 1) -ne "\") {
    $path = $backupbasedir + "\"
}
else {
    $path = $backupbasedir
}

Connect-VIServer $VCenterServer -User $username -Password $password

Get-VMHost | ForEach-Object {
    $path = $path + $_ + "\" + $_.ExtensionData.Config.Product.Version + "\" + $_.ExtensionData.Config.Product.Build
    if (!(Test-Path $path)) { New-Item -ItemType directory -Path $path }
    Get-VMHostFirmware -VMHost $_ -BackupConfiguration -DestinationPath $path
}

此脚本首先在发生证书错误时禁用错误消息,然后遍历特定 vCenter 上的所有主机并将其配置备份到“\ServerName\ESXiVersion\BuildNumber”目录结构

这使得重建特定主机变得非常容易......

  1. 重新安装正确的 ESXi 主版本。
  2. 将其修补到最新备份的正确版本号。我发现最简单的方法是使用命令esxcli software profile update并将其指向所需版本号的正确下载位置。在以下位置找到了正确位置的列表https://tinkertry.com/easy-update-to-latest-esxi在这篇文章发布时。
  3. 使用“Set-VMHostFirmware”命令恢复最新备份:Set-VMHostFirmware -VMHost ESXi_host_IP_address -Restore -SourcePath <Backup Location>
  4. 重新启动并重新连接。

相关内容