Mass Job Duplication

PowerShell script exchange

Mass Job Duplication

Veeam Logoby ekisner » Fri Feb 21, 2014 11:02 pm

I set up a quick powershell script to use a job as a template to create many jobs.

Was hoping someone could look it over and make sure it works as intended... one thing that is not working as intended is the secondary backup (to tape) jobs being copied across. Doing some research on that, and will implement it at some point. I have run it... once... it appeared to do what was intended. Since it appears to have worked on its first run, it is not debugged at all. Review and run with discretion.
Other than that, assuming someone points out a glaring omission, hopefully this will save others some time.

To use it, simply create a backup job, exactly as you want the rest to be. Yes, I could put these as variables at the start, but that's no fun.
You will need to edit:
1) The $vms variable near the beginning
2) The name of the template job to find and use as a template job, 3 lines down
3) Within the foreach loop, edit the naming scheme at the start (mine is simply B2D_<vm name>_PWS).

Code: Select all
#Edit this criteria to select the VMs you want.
$vms = Find-VBRViEntity | ?{$_.criteria -eq "Whatyouwantedtobackup"}

#Select a template job, set up manually via the wizard.  It should be ready to rock and roll.  You will need to edit the name of this job to be the same as what you've defined.
$templatejob = Get-VBRJob -name "B2D_Server01_PWS"
#Get the template job's job options.
$templateoptions = Get-VBRJobOptions $templatejob
#Get the template schedule
$templatesched = Get-VBRJobScheduleOptions $templatejob

#Iterate through each vm in $vms, as gathered by Find-VBRViEntity
foreach ($vm in $vms){
   #Define the job name
   $jobname = "B2D_$($vm.Name)_PWS"

   #Write it to the shell for peace of mind
   write-host $jobname

   #Generate a backup job
   Add-VBRViBackupJob -Name $jobname -BackupRepository (Get-VBRBackupRepository -name PWS*)-entity $vm

   #Find our newly created job
   $job = Get-VBRJob | ?{$_.name -eq $jobname}
   #Add the job options to it
   $job | set-VBRJobOptions -Options $templateoptions
   #Add the job schedule to it
   $job | Set-VBRJobScheduleOptions -Options $templatesched
   #Enable the schedule
   $job.EnableScheduler()
}
ekisner
Expert
 
Posts: 131
Liked: 31 times
Joined: Thu Jul 26, 2012 8:04 pm
Full Name: Erik Kisner

Re: Mass Job Duplication

Veeam Logoby v.Eremin » Sun Feb 23, 2014 7:47 pm

Just a small tip - there is no need to use a template job. Instead, you create a template of job general, as well as schedule settings, and assign these setting to existing jobs. It can be done via New-VBRJobOptions and New-VBRJobScheduleOptions cmdlets.

Anyway, thank you for sharing the script; much appreciated.
v.Eremin
Veeam Software
 
Posts: 13291
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Mass Job Duplication

Veeam Logoby ekisner » Mon Feb 24, 2014 4:57 pm

Yea, the goal here was to be able to use the wizard to create the settings via GUI, more as a measure of peace of mind over anything else.
ekisner
Expert
 
Posts: 131
Liked: 31 times
Joined: Thu Jul 26, 2012 8:04 pm
Full Name: Erik Kisner

Re: Mass Job Duplication

Veeam Logoby v.Eremin » Tue Feb 25, 2014 9:01 am

Yes, there is absolutely no harm to create the "template" job via GUI. You can use whatever approach you like to. Thanks.
v.Eremin
Veeam Software
 
Posts: 13291
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 6 guests