While the Hyper-V management console is cozy and can certainly get the job done, I think there are a handful of PowerShell cmdlets that can make your life easier.
In our environment, we have a bunch of Windows Server 2012 R2 core Edition as hyper-v host with 5o odd VMs running on them. If you are in similar sort of situation and wondering how to quickly restore them if there is a problem, then think about a strategy which meet your needs. It's important to have onsite or offsite backup for disaster recovery, however this article is primarily about Hyper-V Host VMs snapshot to roll back quickly to earlier point. The goal here is to create a snapshot and maintain a limited number of snapshots for a month. This way you can reduce storage issues. However it entirely up to you to decide what suits your needs.
All references are to Hyper-V cmdlets that run on PowerShell 3.0.
So Let us get Started.
Since our is core OS edition without GUI, first we need to create a folder under the root of C-Drive to hold the PowerShell scripts. So if you manage your hyper-v from server manager, right click on Hyper-V host server and select Windows Powershell.
1. Create a folder to store your scripts:
New-Item C:\Scripts –ItemType Directory
2. Create these two PowerShell scripts.
The below is meant to do a weekly snapshot and delete any snapshot older than 31days. Please modify the bit relevant to you, then copy and paste the text from comment which start from # sign into corresponding scripts. These are pretty generic scripts, once you have done that on first Hypervisor server. Simply copy and paste scripts folders on other Hypervisor hosts directly, unless you have different schedule for others.
#This script was created to run weekly snapshots of VMs
Vinnie is an Azure Principal Consultant at Elastabytes. He is originally from India and now living in London. His interests include Film, Fitness, and Cloud Solutions.
You can read Vinnie's personal IT blog here and you can follow him on Twitter @VinnieGrack.
Elastabytes are a cloud managed services company specialising in SQL Server. We’re a Microsoft Gold Partner and our team is made of Microsoft MVPs. Whether you’re already in Azure and need a DBA-as-a-Service, or you’re about to go to Azure and need a hand getting there, Elastabytes can help.
Contact us at firstname.lastname@example.org to set up a chat with one of our architects.