PowerShell script exchange
Post Reply
jyarborough
Veeam ProPartner
Posts: 31
Liked: never
Joined: Apr 03, 2010 2:23 am
Full Name: John Yarborough
Contact:

Set-VBRViReplicaJob issues

Post by jyarborough »

I have searched the forums for "Set-VBRViRepicaJob" and nothing specific came up to what I am looking for so I apologize if I missed an already answered post. I've been working on a wrapper script for bulk creating/editing/maintaining jobs and have noticed a couple of things I'm hoping there is a solution for. This post will focus on "Set-VBRViReplicaJob" issues I'm having.

I have approximately 80 replica jobs (1 per VM, various logic behind this) so bulk editing is critical, especially with how long it takes to click through the interface of a replica job. Anyway, I finally found how to change the replica job to source from backup jobs instead of from the actual VM. (Side note but this has been the #1 feature I have requested for years and I was beyond excited when I found it hidden away in the options for V8! Thank you for listening to my pleas at the trade shows and events!) I couldn't find the options in the Job.Options properties but found that I could set this using "Set-VBRViReplicaJob -ReplicateFromBackup -SourceRepository". I was able to get a script together that set each replica job to source from backup and for the sourcerepository option, I just enumerate all the backup repositories because I don't care so much where it finds the most recent backup, I just want the most recent copy of the data replicated. This part worked great.

First issue: my replica jobs target a cluster, not a host, and when I run Set-VBRViReplicaJob, it seems to change the target to a host in the cluster instead of keeping the cluster. I have a workaround in the script that just keeps track of what it was and then after the Set-VBRViReplicaJob, I use Set-VBRJobOptions to reapply the cluster reference. I believe this also resets the schedule and potentially other settings, but my workaround addresses the major ones I noticed.

Second issue: how do I revert the "-ReplicateFromBackup" option through PowerShell and set it to source from the VM?

Third issue: I recently removed a backup repository and a couple of hosts from the target cluster. Since then, when I run Set-VBRViReplicaJob I get an error on some of the jobs that seems to be indicating a problem finding one of the hosts I removed. I have refreshed my vCenter server object through the GUI and noticed two of the hosts still show up in the inventory even though they no longer exist.

Anyone have any thoughts before I open a support ticket?

Thanks!
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Set-VBRViReplicaJob issues

Post by veremin »

First issue: my replica jobs target a cluster, not a host, and when I run Set-VBRViReplicaJob, it seems to change the target to a host in the cluster instead of keeping the cluster. I have a workaround in the script that just keeps track of what it was and then after the Set-VBRViReplicaJob, I use Set-VBRJobOptions to reapply the cluster reference. I believe this also resets the schedule and potentially other settings, but my workaround addresses the major ones I noticed.
Can you provide both the script that changes a target to a host, instead of a cluster, and the workaround?
Second issue: how do I revert the "-ReplicateFromBackup" option through PowerShell and set it to source from the VM?
The correct script should look like that:

Code: Select all

-ReplicateFromBackup:$False 
There is a bug with -ReplicateFromBackup switch that makes revert process impossible. According to the plan, it should be fixed in one of the next patches. So, thanks for the feedback.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Set-VBRViReplicaJob issues

Post by veremin »

According to the plan, it should be fixed in one of the next patches.
As I've been just notified, the issue is fixed in patch#2. So, stay tuned!
jyarborough
Veeam ProPartner
Posts: 31
Liked: never
Joined: Apr 03, 2010 2:23 am
Full Name: John Yarborough
Contact:

Re: Set-VBRViReplicaJob issues

Post by jyarborough »

I've pulled out the important parts from my bigger script and made this stand alone:

Code: Select all

#############################
# USER VARIABLES

# String to match with -like operator for doing jobs in bulk
$JobNameFilter = "*"

# Set ReplicateFromBackup to be true to enable, false to disable
$ReplicateFromBackup = $true

#############################
# SCRIPT BODY

# Load Veeam snapins
Add-PSSnapin -Name VeeamPSSnapIn

# Get all possible backup repositories, we don't care which one as long as we replicate the latest data
Write-Host "Getting all backup repositories, please wait..."
$AllBackupRepositories = Get-VBRBackupRepository

# Get jobs that match the name filter
$targetJobs = Get-VBRJob | Where { $_.Name -like $JobNameFilter -and $_.IsReplica }
Write-Host ("Processing changes for " + $targetJobs.Count + " job(s):")

# Make the settings change for each job
ForEach ($job In $targetJobs) {
    Write-Host ("Job: [" + $job.Name + "]... ")

    # Store a copy of the job object so we can reference it after things get reset
    $jobOriginal = Get-VBRJob -Name $job.Name

    Write-Host -NoNewline "`tReplicateFromBackup: "
    Try {
        If ($ReplicateFromBackup) {
            Write-Host -NoNewline "enable ... "
            # Set the job to replicate from backup files instead of forcing a second backup window with live data
            Set-VBRViReplicaJob -Job $job -ReplicateFromBackup -SourceRepository $AllBackupRepositories | Out-Null
        }
        Else {
            Write-Host -NoNewline "disable ... "
            Write-Host -NoNewline "!!NOT FUNCTIONAL!! ... "
            # Disable replicating from backup files and reset to use the source VM
            Set-VBRViReplicaJob -Job $job -ReplicateFromBackup:$false | Out-Null
        }

        # Get a fresh job object
        $job = Get-VBRJob -Name $job.Name

        # Reset the job options which were changed unintentionally during the Set-VBRViReplicaJob
        Set-VBRJobOptions -Job $job -Options $jobOriginal.Options | Out-Null
        Set-VBRJobScheduleOptions -Job $job -Options $jobOriginal.ScheduleOptions | Out-Null
        If ($jobOriginal.PreviousJobIdInScheduleChain -ne "") {
            # Check if job was chained, usually is for replicating from backup source
            $jobLinkedSchedule = Get-VBRJob | Where { $_.Id -eq $jobOriginal.PreviousJobIdInScheduleChain }
            Set-VBRJobSchedule -Job $job -After -AfterJob $jobLinkedSchedule.Name | Out-Null
        }
        
        Write-Host "SUCCESS!"
    } 
    Catch { Write-Host "FAILED!" }
}

Write-Host "Finished!"
There are basically two variables at the top: JobNameFilter and ReplicateFromBackup. JobNameFilter would be something like "*sql*" or "*rds*" or whatever makes sense for your environment. Just "*" should process all replica jobs. ReplicateFromBackup is a true/false flag and once the bug is fixed that prevents me from resetting this option, the logic will go in there to get that done.

The only thing in my environment I have found that doesn't get set back up properly is the individual VM mapping to an existing replica. I have another script for that but it is loosely based on Andy's examples but I can provide it if anyone is interested. I obviously wrote this for my environment where all of our naming conventions are highly standardized and the jobs were actually created with a bulk import script I wrote.

I would appreciate any feedback. Still pretty new to PowerShell so if I am doing something that isn't optimal please, by all means, let me know.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Set-VBRViReplicaJob issues

Post by veremin »

Just to keep you updated I've asked QA team to reproduce the described behaviour. Will update the topic, once I have the results of the testings. Thanks.
CraigInEdm
Lurker
Posts: 1
Liked: never
Joined: Feb 23, 2017 10:38 pm
Full Name: Craig Holmes
Contact:

Re: Set-VBRViReplicaJob issues

Post by CraigInEdm »

I have a similar issue with the Set-VBRViReplicaJob command. In my case I have used tags to set what VMs are included, and what credentials to use on each VM since I am working in a multi-domain environment. It all works fine, except I have been trying to set IP rules using a script. Everything seems to work fine, except all the tags used for Guest Processing credentials get added into the list of VMs to replicate. I am using Veeam 9.5 U1. I tried the posted resolution in this post, but it's not fixing my issue. Is there another workaround for this?
dartcz
Novice
Posts: 3
Liked: never
Joined: Aug 16, 2018 1:33 pm
Full Name: dartcz
Contact:

Re: Set-VBRViReplicaJob issues

Post by dartcz »

I have just found this old thread faced the similar issue (trying to change replica metadata repository) :

$repository = Get-VBRBackupRepository -Name "replicaMDrepo"
get-vbrjob | Set-VBRViReplicaJob -BackupRepository $repository

this messed up source virtual machines by filling up the list with random tags and vms used in my enviroment.I have guest processing disabled. Veeam 9.5 U4b. What am I doing wrong ? thank you very much.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Set-VBRViReplicaJob issues

Post by veremin »

So, the script should look similar to the following (don't have a console at hand, so writing from memory):

Code: Select all

$Job = Get-VBRJob -name "Name of your replication job"
$Repository = Get-VBRBackupRepository -Name "Name of your backup repository"
Set-VBRViReplicaJob -Job $Job -BackupRepository $Repository
If this does not work, kindly, reach our support team.

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests