PowerShell script exchange
Post Reply
jmc
Service Provider
Posts: 103
Liked: 9 times
Joined: Sep 12, 2011 11:49 am
Full Name: jmc
Location: Duisburg - Germany
Contact:

Copy a bunch of Backup Job to New Jobs

Post by jmc »

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
"Who brakes late stays fast longer." - "Wer später bremst ist länger schnell"
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Copy a bunch of Backup Job to New Jobs

Post by Sethbartlett »

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.
jmc
Service Provider
Posts: 103
Liked: 9 times
Joined: Sep 12, 2011 11:49 am
Full Name: jmc
Location: Duisburg - Germany
Contact:

Re: Copy a bunch of Backup Job to New Jobs

Post by jmc »

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
"Who brakes late stays fast longer." - "Wer später bremst ist länger schnell"
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Copy a bunch of Backup Job to New Jobs

Post by ThomasMc »

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
jmc
Service Provider
Posts: 103
Liked: 9 times
Joined: Sep 12, 2011 11:49 am
Full Name: jmc
Location: Duisburg - Germany
Contact:

Re: Copy a bunch of Backup Job to New Jobs

Post by jmc »

hello thomas,

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

thx so much.
jeff
"Who brakes late stays fast longer." - "Wer später bremst ist länger schnell"
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Copy a bunch of Backup Job to New Jobs

Post by ThomasMc »

Your welcome :)
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests