Last week I had the task to backup Hyper-V VMs. No Replica, no Clustering, a simple backup with Windows Server Backup. The problem was that a repeating backup job had already been set up. Windows Server Backup allows only one job in the graphic user interface. So, the task was to create a scheduled weekly job with the command line.
I can’t stress it enough, get familiar with PowerShell. More and more extraordinary tasks can only be one in the command line. And believe me, you want to be an extraordinary guy ;-), because it’s pretty cool to make things possible where others give up and buy the next product.
Creating the Backup Job
You have to adjust the command below to your needs. Note the backup target, which is a shared folder on a NAS and the Hyper-V VMs. The quiet parameter is mandatory, because the backup job will ask if you really want to do this. What is your scheduled job in your absence supposed to answer? 😉
wbadmin start backup -backuptarget:\\10.10.0.10\hyper-backup -hyperv:"Server01,Server02" -allowDeleteOldBackups -quietThis backups Server01 and Server02 to 10.10.0.10\hyper-backup.
Now open Notepad copy the command in a file and save this file (*.bat).
For the following make sure Windows Server Backup is installed.
Get-WindowsFeature Windows-Server-Backup
If not, hit the keys and run
Install-WindowsFeature Windows-Server-Backup -IncludeManagementTools
Creating the Scheduled Job
We are able to create a backup job either in the graphical user interface or in PowerShell. Well I think, it’s quite easier to do it in PowerShell, so I’ll show you the PowerShell code. My batch file is saved in C:\Temp\backupVM.bat. The code below creates a scheduled job that will run every Saturday at 11:00 am and is executed as sid-500\administrator. So pay attention to these values. I recommend using PowerShell ISE.
$Action=New-ScheduledTaskAction -Execute 'C:\Temp\backupVM.bat' $Trigger=New-ScheduledTaskTrigger -Weekly -DaysOfWeek Saturday -At 11am $Set=New-ScheduledTaskSettingsSet $Principal=New-ScheduledTaskPrincipal -UserId 'sid-500\administrator' -LogonType S4U $Task=New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Set -Principal $Principal Register-ScheduledTask -TaskName "Backup VM" -InputObject $Task -Force
Fine that’s it.
Windows 10 (Side Note)
I was really surprised about the presence of wbadmin on Windows 10. Thanks to Tom who noticed and commented that the -hyperv parameter is not available on Windows 10.
See you next time with PowerShell again!
Categories: Cyber Security, PowerShell, Windows 10, Windows Server
A critical component volume failed to capture a snapshot. A critical component volume failed to capture a snapshot. This error always happens. I am using Windows Server 2019.
LikeLike
this won’t work on Windows 10, -hyperv is not available :
“One of the parameters or options provided is unexpected: hyperv.”
LikeLike
Thank you for the hint.
LikeLike
hi, hab´s gerade ausprobiert und ich glaube da ist noch ein kleiner Fehler:
wbadmin start backup -backuptarget:\\10.10.0.10\hyper-backup:”Server01,Server02″ -allowDeleteOldBackups -quiet
da fehlt noch ein Attribut
wbadmin start backup -backuptarget:\\10.10.0.10\hyper-backup: -hyperv:”Server01,Server02″ -allowDeleteOldBackups -quiet
lg Markus
LikeLike
Hi Markus! Vielen Dank, ja du hast recht. Fehler können passieren, wenn es allerdings der wichtigste Part ist dann ärgert mich das. Wird ausgebessert sobald ein Rechner in der Nähe ist. Lg P
LikeLike