PowerShell script exchange
Post Reply
Kazz
Expert
Posts: 140
Liked: 17 times
Joined: Feb 08, 2018 3:47 am
Full Name: Kazz Beck
Contact:

replace a proxy on multiple backup jobs

Post by Kazz »

Hi,

I need to change one of my proxies on multiple veeam backup jobs (vmware)
Proxy das-071-vol02 needs to be removed and das-072-vol02 needs to be added only to the jobs where das-071-vol02 is currently configured. (Manual Selection)

The following code gives me a list of all jobs (63) where das-071-vol02 is used. Can anyone assist with a replace logic for VBR proxy from das-071-vol02 to das-072-vol02, while leaving other proxies configured on the 63 jobs as is?

Code: Select all

$proxyName = "das-071-vol02"
$backupJobs = Get-VBRJob
 
# Iterate through each backup job
foreach ($job in $backupJobs) {
    # Check if the job uses the specified proxy
    $proxyUsed = $job | Get-VBRJobProxy #   $job.GetOptions().Proxy
    if ($proxyUsed -ne $null -and $proxyUsed.Name -eq $proxyName) {
        Write-Host "Backup job $($job.Name) uses the proxy ($proxyName)"
    }
}
Thank you
Kazz
Expert
Posts: 140
Liked: 17 times
Joined: Feb 08, 2018 3:47 am
Full Name: Kazz Beck
Contact:

Re: replace a proxy on multiple backup jobs

Post by Kazz »

I am getting an error when running the code below
The property 'Proxy' cannot be found on this object. Verify that the property exists and can be set.

Code: Select all



$oldProxyName = "das-071-vol02"
$newProxyName = "das-021-vol02"

# Get the old proxy
$oldProxy = Get-VBRViProxy -Name $oldProxyName

# Check if the old proxy exists
if ($oldProxy -ne $null) {
    # Get the new proxy
    $newProxy = Get-VBRViProxy -Name $newProxyName

    # Check if the new proxy exists
    if ($newProxy -ne $null) {
        # Replace the old proxy with the new proxy in all backup jobs
        Get-VBRJob | ForEach-Object {
            $jobOptions = $_.GetOptions()
            $jobOptions.Proxy = $newProxy
            $_.SetOptions($jobOptions)
            Write-Host "Replaced proxy for job $($_.Name) from $oldProxyName to $newProxyName"
        }

        # Remove the old proxy
        Remove-VBRViProxy -Proxy $oldProxy
        Write-Host "Removed old proxy $oldProxyName"
    } else {
        Write-Host "New proxy $newProxyName not found"
    }
} else {
    Write-Host "Old proxy $oldProxyName not found"
}


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

Re: replace a proxy on multiple backup jobs

Post by oleg.feoktistov »

Hi Kazz,

Here is the workaround script sample:

Code: Select all

$job = Get-VBRJob -Name 'Backup Job 1'
$oldProxy = Get-VBRViProxy -Name 'Old Proxy'
$newProxy = Get-VBRViProxy -Name 'New Proxy'
$proxyType = [Veeam.Backup.Model.CJobProxyInfo+EType]::ESource
[Veeam.Backup.Core.CJobProxy]::Create($job.Id, $newProxy.Id, $proxyType)
[Veeam.Backup.Core.CJobProxy]::DeleteByProxy($oldProxy.Id)
No matter how many proxies you have assigned in your jobs, it should precisely add the new one and delete the one you specified only.

Then, if you want to delete the old proxy from DB completely, use remove cmdlet:

Code: Select all

Remove-VBRViProxy -Name 'Old Proxy'
Best regards,
Oleg
Kazz
Expert
Posts: 140
Liked: 17 times
Joined: Feb 08, 2018 3:47 am
Full Name: Kazz Beck
Contact:

Re: replace a proxy on multiple backup jobs

Post by Kazz »

Thanks Oleg!
Kazz
Expert
Posts: 140
Liked: 17 times
Joined: Feb 08, 2018 3:47 am
Full Name: Kazz Beck
Contact:

Re: replace a proxy on multiple backup jobs

Post by Kazz »

I am getting Cannot find an overload for "Create" and the argument count: "3".
At line:5 char:1
+ [Veeam.Backup.Core.CJobProxy]::Create($job.Id, $newProxy.Id, $proxyTy ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest


if i give more than one job name to the $job var
Kazz
Expert
Posts: 140
Liked: 17 times
Joined: Feb 08, 2018 3:47 am
Full Name: Kazz Beck
Contact:

Re: replace a proxy on multiple backup jobs

Post by Kazz »

Updated Code

Code: Select all

$oldProxyName = 'das-071-vol02'
$newProxyName = 'das-072-vol02'

$backupJobs = Get-VBRJob

# Loop through each job
foreach ($job in $backupJobs) {
    # Get the old and new proxies for each job
    $oldProxy = Get-VBRViProxy -Name $oldProxyName
    $newProxy = Get-VBRViProxy -Name $newProxyName

    if ($oldProxy -and $newProxy) {
        # Create a new proxy entry for the job
        $proxyType = [Veeam.Backup.Model.CJobProxyInfo+EType]::ESource
        [Veeam.Backup.Core.CJobProxy]::Create($job.Id, $newProxy.Id, $proxyType)
        [Veeam.Backup.Core.CJobProxy]::DeleteByProxy($oldProxy.Id)
        Write-Warning "Proxy replacement completed for job: $($job.Name)"
    } else {
        Write-Warning "Error: Old or new proxy not found for job: $($job.Name)"
    }
}
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests