PowerShell script exchange
Post Reply
FrancWest
Veteran
Posts: 488
Liked: 93 times
Joined: Sep 17, 2017 3:20 am
Full Name: Franc
Contact:

Script to copy settings from periodic copy job to immediate mode copy job.

Post by FrancWest »

Hi,

we are adding a new backup repository and also plan to migrate all our copy jobs from periodic mode to immediate mode.

Since going through all the setting of each copy job and adding them to the new copy job is quite a hassle and prone to errors, I'm looking for a method to quickly migrate the settings from our existing periodic copy jobs to immediate mode copy jobs and also modify the target repository.

Is there some sort of script available that does this, so that I don't have to reinvent the wheel myself? ;-)

Franc.
foggy
Veeam Software
Posts: 21069
Liked: 2115 times
Joined: Jul 11, 2011 10:22 am
Full Name: Alexander Fogelson
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by foggy »

Hi Franc, even if this is not possible with a one-liner, I believe you can create a script to copy the settings one-by-one. Please ask for assistance in the corresponding subforum. Thanks!
FrancWest
Veteran
Posts: 488
Liked: 93 times
Joined: Sep 17, 2017 3:20 am
Full Name: Franc
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by FrancWest »

Hi,

Sorry, can you move this topic to the PowerShell forum to prevent duplicate posts?
Natalia Lupacheva
Veteran
Posts: 1143
Liked: 302 times
Joined: Apr 27, 2020 12:46 pm
Full Name: Natalia Lupacheva
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by Natalia Lupacheva »

Hi Franc,

moved your thread to Powershell subforum.
Also, will leave the discussions on switching from periodic to immediate mode here.

Thanks!
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by oleg.feoktistov » 1 person likes this post

Hi Franc,

Recently I wrote a cmdlet for that purpose.
Please check my GitHub repo for code and instructions.

Any questions are welcome.

Best regards,
Oleg
FrancWest
Veteran
Posts: 488
Liked: 93 times
Joined: Sep 17, 2017 3:20 am
Full Name: Franc
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by FrancWest »

Hi Oleg,

thanks! I've tried your script, but it fails on several places in my setup:

Code: Select all

PS D:\PowershellScripts> Migrate-VBRBackupCopyJob -SourceJob $jobs
Add-VBRViBackupCopyJob : Cannot validate argument on parameter 'Description'. The character length (0) of the argument is too short. Specify an argument with a length that is greater than or
 equal to "1", and then try the command again.
At D:\PowershellScripts\Migrate-VBRBackupCopyJob.ps1:35 char:61
+ ... pyJob -Name $migratedName -Description $sourcejob.Description -Backup ...
+                                            ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-VBRViBackupCopyJob], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.AddVBRViBackupCopyJob
After adding a description to the job:

Code: Select all

PS D:\PowershellScripts> $jobs = Get-VBRJob -Name 'Test job'
PS D:\PowershellScripts> Migrate-VBRBackupCopyJob -SourceJob $jobs
Add-VBRViBackupCopyJob : Cannot validate argument on parameter 'SourceAccelerator'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At D:\PowershellScripts\Migrate-VBRBackupCopyJob.ps1:35 char:126
+ ... cription -BackupJob $linkedJobs -SourceAccelerator $sourceWan -Target ...
+                                                        ~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-VBRViBackupCopyJob], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.AddVBRViBackupCopyJob
Most of my jobs don't have descriptions and I'm not using WAN-accelerators in any of the jobs.

Franc.
Mildur
Product Manager
Posts: 8549
Liked: 2223 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by Mildur » 1 person likes this post

Try to edit the script.
Simply remove everything which is about the wan accelerator.

Example:

Code: Select all

$sourceWan = $sourceJob.FindSourceWanAccelerator()
$targetWan = $sourceJob.FindTargetWanAccelerator()
Or change this command:

Code: Select all

Add-VBRViBackupCopyJob -Name $migratedName -Description $sourcejob.Description -BackupJob $linkedJobs -[u][b]SourceAccelerator $sourceWan -TargetAccelerator $targetWan[/b][/u] -Repository $targetRepository -EnableImmediateCopy
If the parameter is mandatory, use $null as a value instead of the variable
Product Management Analyst @ Veeam Software
FrancWest
Veteran
Posts: 488
Liked: 93 times
Joined: Sep 17, 2017 3:20 am
Full Name: Franc
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by FrancWest »

Well, it doesn't work in my situation.

First I had to add the '-DirectOperation' parameter to the Add-VBRViBackupCopyJob cmdlet since we aren't using wan accelerators. Also, in some periodic copy jobs, we have included VMs as objects instead of backup jobs. When migrating these kind of jobs using the script it fails since immediate mode jobs only allow Backup jobs to be added, not individual VMs.

When migrating such jobs it errors out with:

Code: Select all

Add-VBRViBackupCopyJob : Specify BackupJob parameter.
At D:\PowershellScripts\Migrate-VBRBackupCopyJob.ps1:36 char:5
+     Add-VBRViBackupCopyJob -DirectOperation -Name $migratedName -Desc ...
So I'm going to migrate the jobs manually.

Thanks!

Franc.
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by oleg.feoktistov »

Hi Franc,

Updated the script and included cases when description is empty and job is not using wan accelerators.
So I'm going to migrate the jobs manually.
You'll need to specify backup jobs as includes in the UI anyway. It is the only common include type for both backup copy modes.


Thanks,
Oleg
FrancWest
Veteran
Posts: 488
Liked: 93 times
Joined: Sep 17, 2017 3:20 am
Full Name: Franc
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by FrancWest »

Hi Oleg,

thanks! I understand, but since periodic backup copy jobs allow individual VMs to be added as object, whereas immediate mode job don't allow this, not all copy jobs can be migrated. So there need to be a check in the script for that situation also.

Franc.
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by oleg.feoktistov »

Hi Franc,

Added custom warning listing includes, which won't be added to the target job if their type is unsupported.
Also, added error handling for cases when SourceJob is not of 'BackupSync' type (periodic mode) and backup copy job has already been migrated ( name contains '_migrated' postfix and job type is 'SimpleBackupCopyPolicy').

Hope it helps,
Oleg
FrancWest
Veteran
Posts: 488
Liked: 93 times
Joined: Sep 17, 2017 3:20 am
Full Name: Franc
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by FrancWest »

Thanks! Great work! It works, but I'm getting a warning which is a bit misleading:

WARNING: This cmdlet is no longer supported for computer backup jobs. Use "Get-VBRComputerBackupJob" instead.

Although in this case we still need to use 'Get-VBRJob', the warning is more of an informational message. Of course this has nothing to do with your script, but with the powershell cmdlets, but I thought I'd mention it.
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Script to copy settings from periodic copy job to immediate mode copy job.

Post by oleg.feoktistov »

No worries. Just add -WarningAction SilentlyContinue to the end of Get-VBRJob parameters to suppress this warning. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests