-
- Influencer
- Posts: 11
- Liked: never
- Joined: Apr 08, 2013 11:41 am
- Contact:
Hyper-V Scripting. Creating Job.
So after deciding to create a job for each VM, I started looking at powershell scripting to create the jobs. I cannot find a working example of how to add a Hyper-V machine to a job. There are many examples of doing it for VMWare, that appears to work. This may be a limited example, I consider this to be essential. While documentation for the Powershell api has been difficult at best... (Get-Help is not really documentation) There seems to be a significant difference between what is possible for VMWare and Hyper-V.
-
- Chief Product Officer
- Posts: 31804
- Liked: 7298 times
- Joined: Jan 01, 2006 1:01 am
- Location: Baar, Switzerland
- Contact:
Re: Hyper-V Scripting. Creating Job.
There are no differences between VMware and Hyper-V in terms of PowerShell syntax, so you can use examples both ways. Likewise, all functionality is available for both platforms, which is why I was confused by your "far behind" statement. Also, we do have PowerShell Reference Guide available under Resources tab on the product web page.
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Hyper-V Scripting. Creating Job.
For creating Hyper-V job you can use the following script. It will create a Hyper-V backup job (HV-Test) for two VMs (VM#1, VM#2) that reside on the given host (HyperVHost):I started looking at powershell scripting to create the jobs.
Code: Select all
Asnp VeeamPSSnapin
$HVServer = Get-VBRServer | ?{$_.name -eq "HyperVHost"}
$HVMachines = Find-VBRHvEntity -Server $HVServer | ? {($_.name -eq "VM#1") -or ($_.name -eq "VM#2")}
$Repository = Get-VBRBackupRepository | ? {$_.name -eq "Name of your repository"}
Add-VBRHvBackupJob -Entity $HVMachine -Name "HV-Test" -BackupRepository $Repository
Yep, by now it looks like there is no supported way to add virtual machine to existing Hyper-V job by the means of PowerShell.I cannot find a working example of how to add a Hyper-V machine to a job.
Hope this helps.
Thanks.
-
- VP, Product Management
- Posts: 6035
- Liked: 2860 times
- Joined: Jun 05, 2009 12:57 pm
- Full Name: Tom Sightler
- Contact:
Re: Hyper-V Scripting. Creating Job.
There's not a huge difference in what can be done, but there is one gaping hole, the ability to add VMs to an already existing job. This oversight will be corrected in V7.jeddytier4 wrote:2. So after deciding to create a job for each VM, I started looking at powershell scripting to create the jobs. I cannot find a working example of how to add a Hyper-V machine to a job. There are many examples of doing it for VMWare, that appears to work. This may be a limited example, I consider this to be essential. While documentation for the Powershell api has been difficult at best... (Get-Help is not really documentation) There seems to be a significant difference between what is possible for VMWare and Hyper-V.
-
- Influencer
- Posts: 11
- Liked: never
- Joined: Apr 08, 2013 11:41 am
- Contact:
Re: anyone backing up vm's on csv's without hardware vss?
Code: Select all
Asnp VeeamPSSnapin
$HVServer = Get-VBRServer | ?{$_.name -eq "HyperVHost"}
$HVMachines = Find-VBRHvEntity -Server $HVServer | ? {($_.name -eq "VM#1") -or ($_.name -eq "VM#2")}
$Repository = Get-VBRBackupRepository | ? {$_.name -eq "Repository#2"}
Add-VBRHvBackupJob -Entity $HVMachine -Name "HV-Test" -BackupRepository $Repository
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Hyper-V Scripting. Creating Job.
I tested the aforesaid script with a standalone Hyper-V host and everything seemed to work properly.
I don’t have an access to the Hyper-V cluster right at the moment, so, I’m wondering whether the errors still persist if with the name of your cluster you also specify its type:
The idea is that it might be possible that a standalone host along with a cluster have been added to VB&R console under the same name.
Thanks.
What errors did you get?I kept getting an error when trying to run this.
I don’t have an access to the Hyper-V cluster right at the moment, so, I’m wondering whether the errors still persist if with the name of your cluster you also specify its type:
Code: Select all
Asnp VeeamPSSnapin
$HVServer = Get-VBRServer | ?{($_.name -eq "HyperVHost") –and ($_.type -eq "HvCluster")}
$HVMachines = Find-VBRHvEntity -Server $HVServer | ? {($_.name -eq "VM#1") -or ($_.name -eq "VM#2")}
$Repository = Get-VBRBackupRepository | ? {$_.name -eq "Name of your Repository"}
Add-VBRHvBackupJob -Entity $HVMachine -Name "HV-Test" -BackupRepository $Repository
Thanks.
-
- Influencer
- Posts: 11
- Liked: never
- Joined: Apr 08, 2013 11:41 am
- Contact:
Re: Hyper-V Scripting. Creating Job.
So I take back, most of my nasty thoughts... This did work with some minor edits. I'm working on making it able to copy templated job options, and then I will post it in a separate topic. Also, I swear I was doing something very similar, but didn't realize that the Entity had to be a Machine, not the cluster.
-
- Influencer
- Posts: 11
- Liked: never
- Joined: Apr 08, 2013 11:41 am
- Contact:
Re: Hyper-V Scripting. Creating Job.
Code: Select all
Asnp VeeamPSSnapin
$HVServer = Get-VBRServer | ?{($_.name -eq "HyperVR2") –and ($_.type -eq "HvCluster")}
$HVMachines = Find-VBRHvEntity -Server $HVServer | ? {$_.type -eq "Vm"}
$Repository = Get-VBRBackupRepository | ? {$_.name -eq "VMRepo1"}
foreach($HVMachine in $HVMachines){
$newjob = Add-VBRHvBackupJob -Entity $HVMachine -Name $HVMachine.Name.ToString() -BackupRepository $Repository
$template = Get-VBRJob | where {$_.name -eq "Template"}
$templateoptions = Get-VBRJobOptions $template
$templateoptionsvss = Get-VBRJobVSSOptions $template
$templateoptionssched = Get-VBRJobScheduleOptions $template
Set-VBRJobOptions -job $newjob -options $templateoptions
Set-VBRJobVSSOptions -job $newjob -options $templateoptionsvss
Set-VBRJobScheduleOptions -job $newjob -options $templateoptionssched
}
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Hyper-V Scripting. Creating Job.
Can you shed a little more light on what you’re trying to achieve, so, someone from community will probably be able to help you?I'm working on a more detailed one, to try to split the jobs up by hos, but not having much luck yet.
Thanks.
-
- Influencer
- Posts: 11
- Liked: never
- Joined: Apr 08, 2013 11:41 am
- Contact:
Re: Hyper-V Scripting. Creating Job.
Having 100 or more individual job is pretty untenable as well. I'm working on an alternative based off of the CSV that the machines are running on. I haven't had a chance to look yet, but will update this thread with the code eventually.
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Hyper-V Scripting. Creating Job.
If you have a cluster and you’re willing to backup within one job all VMs that reside on a specific host, you can put into use the following script:I'm working on a more detailed one, to try to split the jobs up by hos, but not having much luck yet.
Code: Select all
asnp VeeamPSSnapin
$Hostname = Read-Host "Enter the host's name"
$HvServer = (Get-VBRServer | ? {($_.name -eq “Your cluster’s name”) -and ($_.Type -eq "HvCluster")}).GetChilds() | ? {($_.name -eq $Hostname) -and ($_.Type -eq "HvServer")}
$HVMachines = Find-VBRHvEntity -Server $HVServer | ? {$_.type -eq "VM"}
$Repository = Get-VBRBackupRepository | ? {$_.name -eq "Name of your repository"}
Add-VBRHvBackupJob -Entity $HVMachines -Name "Name of your job" -BackupRepository $Repository
Is this you’re looking for?
Hope this helps.
Thanks.
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Hyper-V Scripting. Creating Job.
Otherwise, you might want to try something that looks a little bit shorter :
Please test both of the proposed variants before implementing. As I’ve said previously, I don’t have a Hyper-V cluster in my lab, so, it’s rather hard to guess whether everything is ok with aforesaid scripts.
Hope this helps.
Thanks.
Code: Select all
Asnp VeeamPSSnapin
$Hostname = Read-Host "Enter the host's name"
$HvCluster = Get-VBRServer | ? {($_.name -eq “Your cluster’s name”) -and ($_.Type -eq "HvCluster")}
$HVMachines = Find-VBRHvEntity -Server $HVCluster | ? {($_.type -eq "VM") -and ($_.VmHostName -eq $Hostname)}
$Repository = Get-VBRBackupRepository | ? {$_.name -eq "Name of your repository"}
Add-VBRHvBackupJob -Entity $HVMachines -Name "Name of your job" -BackupRepository $Repository
Please test both of the proposed variants before implementing. As I’ve said previously, I don’t have a Hyper-V cluster in my lab, so, it’s rather hard to guess whether everything is ok with aforesaid scripts.
Hope this helps.
Thanks.
Who is online
Users browsing this forum: No registered users and 17 guests