Tuesday 3 December 2013

Hyper-V 2012 R2 Export / Backup Script

Our backup tool of choice for our virtual infrastructure is Acronis Backup and Recovery Virtual Edition 11.5. However recently we had issues with it on our new Hyper-V 2012 R2 Servers.

We needed some backups while we fixed the issues with Acronis so I created this powershell script to export all the vms on each of our Hyper-V servers.

The script loops through all virtual machines on the local Hyper-V server and exports the virtual machine to the backup location specified in $path. The exported files are stored in a folder named with todays date inside a folder with the name of the virtual machine.

Example \\[path backup location]\testVM\2013-12-03\

--Start of script--

$path = ""
$vms = Get-VM
foreach ($vm in $vms) {
    $date = Get-Date -format “yyyy-MM-dd”
    $vmname = $vm.Name
    New-Item -ItemType Directory -Path $path\$vmname\$date -Force
    Export-VM -Name $vmname -Path $path\$vmname\$date\
}


--End of script--

Notes:

This script has only been used on Hyper-V 2012 R2 servers as this version allows virtual machines to be exported while the virtual machine is running.

I have had to run the script on the local Hyper-V server. It doesn't work when ran from a remote console.

As with any script please test it before using in production as there is no warranty with this script.

Hope it helps some one.

6 comments:

Unknown said...

Thanks alot. This helped me much.

Sony said...

Good to hear it helped you. Thanks Raghavendra

dhivya said...

This information is impressive. I am inspired with your post writing style & how continuously you describe this topic. Eagerly waiting for your new blog keep doing more.
Digital Marketing Training in Chennai
JAVA Training in Chennai
Java classes in chennai
Android Training in Chennai
Qtp training in Chennai

Kevin Dellinger said...

Wow, fantastic weblog format! How long have you ever been running a blog for? You made running a blog, glance easy. The total glance of your website is wonderful, let alone the content! Click to find out more: How To Lock Files From Scratch

Anonymous said...

You know your projects stand out of the herd. There is something special about them. It seems to me all of them are really brilliant!ISO 11612

Anonymous said...

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck. Orthopedic Surgeon