Windows Server Backup Notes
Windows Server Backup is a free, optional tool to create backups of volumes, both OS and Data, as separate backups. With a bit of scripting, you could create a reasonable backup solution if dedicate third party solutions are out of reach.
By default, wbadmin will create a folder called 'WindowsImageBackup' on the target path. When you can rename this folder, you will need to rename it back to its original name to perform a restore.
Installing wbadmin for Windows Server:
Open PowerShell with elevated privileges and run the following:
Here are some examples on using Windows Server Backup, wbadmin:
Creating a backup of a Hyper-V guest:
wbadmin start backup -backupTarget:E: -hyperv:"MyVM" -quiet
List backup versions:
wbadmin get versions
Get specific details of a particular backup. Read more here.
wbadmin get items -version:12/26/2018-11:19
Performing a restore of a Hyper-V guest;
wbadmin start recovery -version:12/26/2018-12:00 -itemType:hyperv -items:"MyVM" -backupTarget:E:
Example: PowerShell script to automate a VM guest backup on Hyper-V:
#Declare variables, req. Install-Module Posh-SSH and mc-wol.exe or alternative WOL utility$NAS = "192.168.1.10"$NASUser ="nasuser"$NASPwd = ConvertTo-SecureString "blablablablablabla" -AsPlainText -Force$NASCred = New-Object System.Management.Automation.PSCredential($NASUser, $NASPwd)$NewPSDriveCred = New-Object System.Management.Automation.PsCredential("$NAS\$NASUser", $NASPwd)$NASMAC = "11:22:33:aa:bb:cc"$BackupPath = "X:\Backups\"$env:Path += ";C:\Scripts\SystemBackup"$DateFolder = "$((Get-Date).ToString('yyyyMMdd'))"Clear-HostWrite-Host ""Write-Host "Waking up NAS..." -foreground yellowWrite-Host ""mc-wol.exe $NASMACClear-HostWrite-Host ""Write-Host "Waiting for NAS..." -foreground yellowWrite-Host ""#Adjust sleep timer to suit your NAS applianceStart-Sleep 180$Ping = Test-Connection -ComputerName $NAS -Count 1 -QuietIf ($Ping -eq $false){Clear-HostWrite-Host ""Write-Host "NAS is offline, exiting..." -foreground redWrite-Host ""Exit}Else{Clear-HostWrite-Host ""Write-Host "Commencing VM Backup" -foreground yellowWrite-Host ""}#Run VM backupsRemove-Item -Recurse "E:\WindowsImageBackup"wbadmin start backup -backupTarget:E: -hyperv:"somevm" -quietMove-Item -Path "E:\WindowsImageBackup" -Destination "E:\$DateFolder"New-PSDrive –Name "X" -PSProvider FileSystem -Root "\\$NAS\share" -Credential $NewPSDriveCred#Retains 7 days of backups, purging the restGet-ChildItem "$BackupPath" | Where-Object {$_.CreationTime -le (Get-Date).AddDays(-7)} | Foreach-Object {Remove-Item $_.FullName -Recurse -Verbose -Force} Copy-Item "E:\$DateFolder\" -Destination "$BackupPath" -RecurseRemove-PSDrive -name "X" -Force#Shutting down NASNew-SSHSession -ComputerName $NAS -Credential $NASCredInvoke-SSHCommand -Index 0 -Command "shutdown -p now"Remove-SSHSession -Index 0 -Verbose#Tidy up local backupMove-Item -Path "E:\$DateFolder" -Destination "E:\WindowsImageBackup"Clear-HostWrite-Host ""Write-Host "VM Backup is Complete!" -foreground greenWrite-Host ""Exit