-
- Novice
- Posts: 5
- Liked: never
- Joined: Sep 06, 2013 5:55 am
- Full Name: René Schärer
- Contact:
automatically disable/enable Jobs
Hi
We use the logical folder in vCenter to Backup the VM. Each Folder has a backup job (with different Options).
Our environment is really dynamic.
Now sometimes there are no VM in folders but the backup job is enabled.
Is it possible to create a Powershell script which match following points:
- go through all Job's and scan the number of VM's or amount of space to backup.
- if the number or amount zero the job should be automatically disabled if it enabled.
- if something in the backup job and is disabled it should be enabled automatically.
regards
René
We use the logical folder in vCenter to Backup the VM. Each Folder has a backup job (with different Options).
Our environment is really dynamic.
Now sometimes there are no VM in folders but the backup job is enabled.
Is it possible to create a Powershell script which match following points:
- go through all Job's and scan the number of VM's or amount of space to backup.
- if the number or amount zero the job should be automatically disabled if it enabled.
- if something in the backup job and is disabled it should be enabled automatically.
regards
René
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: automatically disable/enable Jobs
Hi, René. From my perspective, the following script should meet your expectations:
Thanks.
Code: Select all
asnp VeeamPSSnapin
foreach ($Job in (Get-VBRJob | ?{$_.jobtype -eq "Backup"}))
{
if ($Job.info.IncludedSize -eq 0) {$Job.DisableScheduler()}
}
-
- Novice
- Posts: 9
- Liked: 1 time
- Joined: Sep 25, 2013 6:43 am
- Full Name: Laura
- Contact:
Re: automatically disable/enable Jobs
Hi!
The script works fine. Thanks!
I updated the script with an additional function to enable all other jobs:
But there's one little problem... The recalculation of the size (into a job) doesn't update automatically.
So, empty jobs on which you add new VMs will stay disabled because the size is still 0.0kb. If you remove all VMs on a enabled job it should be 0.0kb but it doesn't update it.
We think the reason for this problem is that we work with logical folders from the vCenter in the job.
Has anybody an idea for a workaround?
Thanks!
Regards
Laura
The script works fine. Thanks!
I updated the script with an additional function to enable all other jobs:
Code: Select all
asnp VeeamPSSnapin
foreach ($Job in (Get-VBRJob | ?{$_.jobtype -eq "Backup"}))
{
IF ($Job.info.IncludedSize -eq 0) {$Job.DisableScheduler()}
ELSE
{
$Job.EnableScheduler()
}
}
So, empty jobs on which you add new VMs will stay disabled because the size is still 0.0kb. If you remove all VMs on a enabled job it should be 0.0kb but it doesn't update it.
We think the reason for this problem is that we work with logical folders from the vCenter in the job.
Has anybody an idea for a workaround?
Thanks!
Regards
Laura
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: automatically disable/enable Jobs
Hi, Laura. I’m wondering what the version you’re using. Is it still the case with version 7? Thanks.
-
- Novice
- Posts: 9
- Liked: 1 time
- Joined: Sep 25, 2013 6:43 am
- Full Name: Laura
- Contact:
Re: automatically disable/enable Jobs
Hi Vladimir. We're using version 6.5 (6.5.0.144). We plan the update to v7 next week. Do you think the problem will be solved with v7?
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: automatically disable/enable Jobs
Yep, I believe so. The approximate size showing mechanism should have been fixed there. Thanks.
-
- Novice
- Posts: 9
- Liked: 1 time
- Joined: Sep 25, 2013 6:43 am
- Full Name: Laura
- Contact:
Re: automatically disable/enable Jobs
Nice! So, we will see next week. Thanks!
-
- Novice
- Posts: 9
- Liked: 1 time
- Joined: Sep 25, 2013 6:43 am
- Full Name: Laura
- Contact:
Re: automatically disable/enable Jobs
We updated last Wednesday - Unfortunately the approximate size showing problem is still the same. It will be the easiest way to create a powershell script which will readout from vCenter directly. I think the problem is because we work with logical folders from the vCenter and not with directly added VMs...
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: automatically disable/enable Jobs
Then, you might want to use PowerCLI, as well. The algorithm should be as the following:
1) Get the name of the folder from the backup job. (VeeamPSSnapin)
2) Connect to vCenter and check whether there are any VMs located under the said folder (PowerCLI)
3) If the answer is yes, enable the backup job, otherwise, disable it.
So, if every backup job uses folder as a source, you should utilize something like this:
Thanks.
1) Get the name of the folder from the backup job. (VeeamPSSnapin)
2) Connect to vCenter and check whether there are any VMs located under the said folder (PowerCLI)
3) If the answer is yes, enable the backup job, otherwise, disable it.
So, if every backup job uses folder as a source, you should utilize something like this:
Code: Select all
add-pssnapin VMware.VimAutomation.Core
Add-PSSnapin VeeamPSSnapin
Connect-VIServer -Server "Name of vCenter" -User "user" -Password "password"
foreach ($Job in (Get-VBRJob | ?{$_.jobtype -eq "Backup"}))
{
$Foldername = $Job | Get-VBRJobObject | select name
$Folder = Get-Folder -name $Foldername
If ((Get-VM -Location $Folder) -eq $null) {$Job.DisableScheduler()}
Else {$Job.EnableScheduler()}
}
-
- Novice
- Posts: 9
- Liked: 1 time
- Joined: Sep 25, 2013 6:43 am
- Full Name: Laura
- Contact:
Re: automatically disable/enable Jobs
Hi Vladimir. Thank you very much for your help and the script! Now I am happy!
I updated the script a little bit and now it works fine for me:
1) Save creds into a file:
2) Updated script (updated line: $Foldername = $Job | Get-VBRJobObject | ForEach-Object {$_.name}):
I updated the script a little bit and now it works fine for me:
1) Save creds into a file:
Code: Select all
Add-PSSnapIn VMware.VimAutomation.Core
New-VICredentialStoreItem -host "vCenter Server" -user "user" -password "password" -file C:\Scripts\credfile.xml
Code: Select all
Add-PSSnapin VMware.VimAutomation.Core
Add-PSSnapin VeeamPSSnapin
$creds = Get-VICredentialStoreItem -file “C:\Scripts\credfile.xml”
Connect-viserver -Server $creds.Host -User $creds.User -Password $creds.Password
foreach ($Job in (Get-VBRJob | ?{$_.jobtype -eq "Backup"}))
{
$Foldername = $Job | Get-VBRJobObject | ForEach-Object {$_.name}
$Folder = Get-Folder -name $Foldername
If ((Get-VM -Location $Folder) -eq $null) {$Job.DisableScheduler()}
Else {$Job.EnableScheduler()}
}
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: automatically disable/enable Jobs
Glad to hear that my input was helpful. Should any other questions arise, don’t hesitate to let us know. Thanks.
Who is online
Users browsing this forum: No registered users and 10 guests