我正在尝试设置一个脚本,仅使用 WBADMIN 来运行虚拟机的备份,我已经能够使用新的 -HyperV 开关备份所有虚拟机,但是我还想备份 HyperV 主机组件。有没有人有这方面的经验,或者可以给我一些文档(微软忽略了这个新的 -HyperV 开关)
如果你感兴趣的话这是我的 powershell 脚本:
#Constant Variables
$Day = Get-Date
$Day = $Day.DayOfWeek
$Date = Get-Date -format hhmmddMMyyyy
$Server = hostname
#Set Paths
$BackupPath = "\\backup\Backups\" + $Server + "\" +$Day
$LogPath = "\\backup\Backups\" + $Server + "\Logs\" + $Date +".txt"
# SELECT Virtual Machines
$VMList = $null
$VMs = Get-VM | Select-Object VMId
for ($i = 0 ; $i -lt $VMs.length ; $i++) {
$VMList = $VMList + '"' + $VMs[$i].VMId + '"' +","
}
$VMList = $VMList.Substring(0,$VMList.Length - 1)
#Run Backup
WBADMIN START BACKUP -backupTarget:$BackupPath -hyperv:$VMList -Quiet
答案1
所以我最终发现你需要放弃 WBADMIN,转而使用 powershell 中的 WBbackup CMDLETS,具体操作如下
#Constant Variables
$Day = Get-Date
#Use this for Backups in Evening
$Day = ($Day.AddDays(1)).DayOfWeek
#Use this for Backups in the Morning
#$Day = $Day.DayOfWeek
$Date = Get-Date -format hhmmddMMyyyy
$Server = hostname
$Target = '\\backup\backups\'+$Server+'\'+$Day
$VirtualMachines = Get-WBVirtualMachine
$DailyFullWB = New-WBPolicy
$BackupTarget = New-WBBackupTarget -NetworkPath $Target
Set-WBPolicy -Policy $DailyFullWB
Add-WBBackupTarget -Policy $DailyFullWB -Target $BackupTarget -Force
Add-WBVirtualMachine -Policy $DailyFullWB -VirtualMachine $VirtualMachines
Start-WBBackup -Policy $DailyFullWB -AllowDeleteOldBackups -Force
答案2
实际上,这个解决方案太容易让人相信了,而且确实没有文档记录。实际上,您“只需”在 VMlist(参数--hyperv
)中包含字符串“Host Component”。
只要记住它包含一个空格,因此您需要用引号括住该字符串。
例如这样:
wbadmin start backup -backupTarget:$BackupPath -hyperv:"$VMList,Host Component" -quiet
至少在 Windows Server 2016 中这是可行的。