![使用 powershell 備份 Windows 伺服器](https://rvso.com/image/1618332/%E4%BD%BF%E7%94%A8%20powershell%20%E5%82%99%E4%BB%BD%20Windows%20%E4%BC%BA%E6%9C%8D%E5%99%A8.png)
我想在完成後測試備份,確認我可以還原哨兵檔案。
我們都知道,頻繁的備份以及隨後在不同環境中的儲存、複製可以提供額外的安全性。為此,我們的備份儲存伺服器(名為Vault
)保留了日常備份的多個額外副本。
測試範例程式碼:
$Backup = '\\localhost\d$\Vault\One'
$ex =""
try{
# I have no clue how to get the servers from Get-WBBackupSet, so, resort to parsing the error
# Get-WBBackupSet error response when multiple backups are stored:
#Backups of multiple computers are in the backup storage location. The computers for which backups are present are:
#bdc iis myblue quickbooks sqlserver <redacted> .
#Please specify the computer that you want to manage backups for.
$servers=@{}
Get-WBBackupSet -BackupTarget $BackupTarget
} catch {
$m=($_ -split "`r`n")[0]
$ix=$m.IndexOf(":")
$l=$m.Substring($ix+1)
$ix=$l.IndexOf(" . ")
$Servers=$($l.Substring(0,$ix).split(" "))|? {$_ -ne ''} }
$servers | %{
$BackupSet = Get-WBBackupSet -BackupTarget $BackupTarget -MachineName $_
Write-host " $("$_".PadRight(12))$($($BackupSet.BackupTime).ToString("yyyy-MM-dd hh:mm tt ddd"))"
$BackupSet.Volume | ? { $_.MountPath -ne '' } | % {
$V=$_
Write-Host $($v.VolumeLabel.PadRight(12)) $($v.MountPath.PadRight(6)) " `
"$(($_.FreeSpace/1GB).tostring("n2").PadLeft(8))Gb $(($_.TotalSpace/1GB).ToString("n2").PadLeft(8))Gb "
Get-WBBackupVolumeBrowsePath -VolumeInBackup $_ -BackupSet $BackupSet
}
}
我無法開始Get-WBBackupVolumeBrowsePath
恢復儲存在每個磁碟區上的眾所周知的哨兵檔案:
"\\localhost\d$\Vault\One"
admin 2020-03-13 07:00 PM Fri
C: 21.38GB 59.46GB
Get-WBBackupVolumeBrowsePath : an attempt to retrieve the properties for the backup set
failed because the backup set is not in the catalog.
at "C:\Repos\PowerShell\BackupStatus.ps1":... char:13
+ Get-WBBackupVolumeBrowsePath -VolumeInBackup $_ -Backup ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WBBackupVolumeBrowsePath], Exception
+ FullyQualifiedErrorId : System.Exception,Microsoft.Windows.ServerBackup.Commands.GetWBBackupVolumeBrowsePath
在哪裡或如何引用目錄?使用WBbackup
,我可以打開並檢索來自 的單個文件Vault
,但我有大約 25 個伺服器的備份需要檢查!
答案1
Get-BackupSet
其本身將傳回系統目錄中的所有備份集。您應該能夠使用其中任何一個,但Get-WBBackupVolumeBrowsePath
似乎要求備份集位於您的系統目錄(而不是其他路徑)中,以便能夠在背景以互動方式安裝它。
您可以直接恢復檔案而不需要WBBackupVolumeBrowsePath
,並檢查恢復是否有錯誤:
Start-WBFileRecovery -BackupSet $BackupSet -FilePathToRecover "C:\Dir1" -Recursive -FileRecoveryOption CreateCopyIfExists -Force