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--


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.


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

Tuhin said...

keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
digital marketing training in bangalore | https://www.excelr.com/digital-marketing-training-in-bangalore

saran said...

I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog.
Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery

smartdeveloper said...

Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article.
Thanks for sharing such a nice info.I hope you will share more information like this. please keep on sharing!

internship in chennai
internship in chennai for cse
internship for mba in chennai
internship in chennai for hr
internship in chennai for mba
companies for internship in chennai
internship in chennai for ece
paid internship in chennai
internship in chennai for biotechnology
internship in chennai for b.com students

invincible01 said...

Amazing Article, Really useful information to all So, I hope you will share more information to be check and share here.

Jupyter Notebook
Jupyter Notebook Online
Jupyter Notebook Install
Automation Anywhere Tutorial
Rpa automation anywhere tutorial pdf
Automation anywhere Tutorial for beginners
Kivy Python
Kivy Tutorial
Kivy for Python
Kivy Installation on Windows