Copy a bunch of Backup Job to New Jobs

PowerShell script exchange

Copy a bunch of Backup Job to New Jobs

Veeam Logoby jmc » Fri Dec 30, 2011 8:10 pm

hello @,

i have approx. 100 backup jobs and i want to create new once from this existing under new name - might be a new suffix. i need this for changing the backup repository without removing the old backups from database.

i'm searching on a script to take one by one backup job, give it a new name like job-01 as original and job-new-01 after copy.

thanks
jeff
Everybody ask why the dinosaurs are gone - nobody ask why they are lived so long
jmc
Service Provider
 
Posts: 26
Liked: never
Joined: Mon Sep 12, 2011 11:49 am
Location: Duisburg - Germany
Full Name: jmc

Re: Copy a bunch of Backup Job to New Jobs

Veeam Logoby Sethbartlett » Fri Dec 30, 2011 8:13 pm

I will take a look this weekend and see what can be done. Do you need the whole job copied, VMs in the job included, etc?
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Copy a bunch of Backup Job to New Jobs

Veeam Logoby jmc » Fri Dec 30, 2011 8:27 pm

hello seth,

that would be very nice. YES, everything should be copied. after this copy i will change the backup repository in each job.
ok, the best way would be to define the new repository in this script.

when you have enough waste time :-)
you can define also the compression ratio and the storage optimization.

thanks
jeff
Everybody ask why the dinosaurs are gone - nobody ask why they are lived so long
jmc
Service Provider
 
Posts: 26
Liked: never
Joined: Mon Sep 12, 2011 11:49 am
Location: Duisburg - Germany
Full Name: jmc

Re: Copy a bunch of Backup Job to New Jobs

Veeam Logoby ThomasMc » Fri Jan 06, 2012 12:37 am

This should be everything apart from renaming the original job, have a play about with it in the lab and if anything needs changed just say the word

Usage;

Code: Select all
#Define job and repo
PS C:\> $job = Get-VBRJob -Name "Backup Job 4"
PS C:\> $repo = Get-VBRBackupRepository -Name "Offsite Repo"

#Copy Backup Job 4 on Offsite Repo with Best Compression and Wan Target
PS C:\> Copy-vPCViBackupJob $job $repo " Wan Backup" "Best" "Wan"

#Copy Backup Job 4 on Onsite Repo with Optimal Compression and Lan Target
PS C:\> Copy-vPCViBackupJob $job "Onsite Repo" " Lan Backup" "Optimal" "Lan"

#Copy Backup Job 5 on Default Backup Repository with Low Compression and Local Target
PS C:\> Copy-vPCViBackupJob "Backup Job 5" "Default Backup Repository" " Local Backup" "Low" "Local"


Script;

Code: Select all
function Copy-vPCViBackupJob {
   param(
      [PsObject]$job,
      [PsObject]$repo,
      [String]$newString = " Copy",
      [String]$CompressionLevel,
      [String]$StgBlockSize
      )
   Begin {
      # Check the job and repo param, if string then retrive objects
      if($Job.getType().Name -eq [String]){
         $Job = Get-VBRJob -Name $Job
      }
      if ($repo -ne $null) {
         if($repo.getType().Name -eq [String]){
            $repo = Get-VBRBackupRepository -Name $Repo
         }
      }
      else {
         $repo = $job.FindTargetRepository()
      }
      # Array to hold the VI Entities we will be adding to the job
      $ViEntities = @()
      # Fetch the job objects we want to clone to the new job
      $jobObjects = $job.GetObjectsInJob()
      $jobOptions = $job.GetOptions()
      if ($CompressionLevel.ToString().Trim() -ne "") {
         if ($CompressionLevel.ToLower() -eq "best") {
            $Compval = 9
         }
         elseif ($CompressionLevel.ToLower() -eq "optimal") {
            $Compval = 6
         }
         elseif ($CompressionLevel.ToLower() -eq "low") {
            $Compval = 4
         }
         elseif ($CompressionLevel.ToLower() -eq "none") {
            $Compval = 0
         }
         
         $jobOptions.BackupStorageOptions.CompressionLevel = $Compval
      }
      if ($StgBlockSize.ToString().Trim() -ne "") {
         if ($StgBlockSize.ToLower() -eq "local") {
            $Stgval = "KbBlockSize1024"
         }
         elseif ($StgBlockSize.ToLower() -eq "lan") {
            $Stgval = "KbBlockSize512"
         }
         elseif ($StgBlockSize.ToLower() -eq "wan") {
            $Stgval = "KbBlockSize256"
         }
         
         $jobOptions.BackupStorageOptions.StgBlockSize = $Stgval
      }
      $jobVSS = $job.GetVssOptions()
      $jobSchedule = $job.GetScheduleOptions()
      # Set the new job name
      $newJobName = $job.Name + $newString
   }
   Process {
      # loop through the job objects and find the ViEntity
      foreach ($vm in $jobObjects) {
         $vmObj = $vm.GetObject().Info
         $viPathAry = $vmObj.Path.Split("\")
         $viServer = Get-VBRServer -Name $viPathAry[0]
         $ViEntities += Find-VBRViEntity -Server $viServer -Name $vm.Name
      }
      # Add the new Vi Backup Job
      Add-VBRViBackupJob -Name $newJobName -BackupRepository $repo -Entity $ViEntities | Out-Null
      # Set the options to the new job
      $newJob = Get-VBRJob -Name $newJobName
      $newJob.SetOptions($jobOptions) | Out-Null
      $newJob.SetVssOptions($jobVSS) | Out-Null
      
      $newJob | Set-VBRJobScheduleOptions -Options $jobSchedule | Out-Null
      

   }
   End {
      # Return the new job
      $newJob
   }
}


*Note: no per VM VSS is copied only the default VSS, V6 only
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Copy a bunch of Backup Job to New Jobs

Veeam Logoby jmc » Fri Feb 03, 2012 9:26 am

hello thomas,

great script and VERY usefull. that's exact what i searched.

thx so much.
jeff
Everybody ask why the dinosaurs are gone - nobody ask why they are lived so long
jmc
Service Provider
 
Posts: 26
Liked: never
Joined: Mon Sep 12, 2011 11:49 am
Location: Duisburg - Germany
Full Name: jmc

Re: Copy a bunch of Backup Job to New Jobs

Veeam Logoby ThomasMc » Fri Feb 03, 2012 3:50 pm

Your welcome :)
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 8 guests