PowerShell script exchange
Post Reply
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

PS1 to move client from protection group A to protection gropu B

Post by karapoti »

Hi,

I've got a bazillion RHEL clients to import into Veeam, where I've given the RHEL admins a protection group XML config file for them to ansible-ise the installation of agent software/place private key file/modify /etc/sudoers - all which works well.

I'm trying to figure out how to use powershell to take a list of client names and move them from the 'landing zone' protection group and put them in a group that I specify.

I can find a list of clients in the protection group (get-vbrdiscoveredcomputer -protectiongroup ASDF | select Name) but can't figure out how to take those objects and move them into an existing protection group...

Does anyone have some advice?
cheers
Adrian
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: PS1 to move client from protection group A to protection gropu B

Post by oleg.feoktistov »

Hi Adrian,

The way with Get-VBRDiscoveredComputer won't work because VBRDiscoveredComputer class represents the state of a host after it was added to a protection group. Instead you could query initial specs for hosts in each protection group, compare source and target protection groups, create new specs based on hosts you want to move and pass those specs to add/remove hosts from protection groups. For example:

Code: Select all

# Source Protection Group
$pg1 = Get-VBRProtectionGroup -Name 'Manually Added'

# Target Protection Group
$pg2 = Get-VBRProtectionGroup -Name 'Test' 


# Names of the hosts to be moved
$hostNames = ("host1", "host2")

# Getting source and target specs from protection groups
$container1 = $pg1.Container
$container2 = $pg2.Container
$customCreds1 = $container1.CustomCredentials
$customCreds2 = $container2.CustomCredentials

# Forming new specs based on move criterias
$customCreds3 = $customCreds1 | ? {$_.HostName -in $hostNames} 
$customCreds4 = $customCreds1 | ? {$_ -notin $customCreds3}
$sum = $customCreds2 + $customCreds3

<# Assigning new specs to the existing protection groups. 
Adding hosts to the target group and then removing them from the source group #>

$container1 = Set-VBRIndividualComputerContainer -Container $container1 -CustomCredentials $customCreds4
$container2 = Set-VBRIndividualComputerContainer -Container $container2 -CustomCredentials $sum
Set-VBRProtectionGroup -ProtectionGroup $pg2 -Container $container2
Set-VBRProtectionGroup -ProtectionGroup $pg1 -Container $container1
Start-Sleep -Seconds 5

# Rescanning protection groups
Rescan-VBREntity -Entity @($pg1, $pg2)
Hope it helps,
Oleg
karapoti
Influencer
Posts: 14
Liked: 1 time
Joined: Apr 12, 2018 12:22 am
Full Name: Adrian Robinson
Contact:

Re: PS1 to move client from protection group A to protection gropu B

Post by karapoti »

Thanks Oleg!

Something wrong/different in that the source PG is a 'manually deployed' PG, so I can't extract the customer credentials:

Code: Select all

PS C:\Windows\system32> $container1 = Set-VBRIndividualComputerContainer -Container $container1 -CustomCredentials $customCreds4
Set-VBRIndividualComputerContainer : Cannot bind parameter 'Container'. Cannot convert the "ManuallyDeployed" value of type "Veeam.Backup.PowerShell.Infos.VBRManuallyDeployedContainer" to type 
"Veeam.Backup.PowerShell.Infos.VBRIndividualComputerContainer".
At line:1 char:61
+ ... 1 = Set-VBRIndividualComputerContainer -Container $container1 -Custom ...
+                                                       ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-VBRIndividualComputerContainer], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Cmdlets.SetVBRIndividualComputerContainer
    
   
    PS C:\Windows\system32> $pg1.Container


Path             : 
LinuxPackages    : {}
UnixPackages     : {}
IsWindowsChecked : False
IsLinuxChecked   : False
IsUnixChecked    : False
IsMacChecked     : False
Type             : ManuallyDeployed

vs 


    PS C:\Windows\system32> $pg2.Container

CustomCredentials                                                                                      Type
-----------------                                                                                      ----
{fqdn1.com, fqdn2.com, fqdn3.com} IndividualComputers
    
    
Can probably figure out how to add the client to PG2, but like there's no way to update the source PG because the Container details don't exist...



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

Re: PS1 to move client from protection group A to protection gropu B

Post by oleg.feoktistov »

Hi Adrian,

I'm sorry, I believe I missed the whole point you emphasized on initially and confused protection groups with pre-installed agents for manually added protection group. For groups with manually deployed packages it is indeed not possible to just obtain containers with credentials objects and re-save to another protection group. Looks like with xml config file all the communication between agents and VBR server happens using certificates. I don't see that any credentials are saved to an xml config or DB whatsoever in this scenario.
So, the way I think it could work is if you compare host names you want to move with the host names in a protection group, then add credentials for each of them using Add-VBRCredentials and create new computer containers with newly added credentials.

Best regards,
Oleg
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: PS1 to move client from protection group A to protection gropu B

Post by masonit »

Hi!

I have a server that somehow is in protection group "Manually Added". I now want to move it to another pg. Server is in 2 active backup jobs. How can this be done?

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

Re: PS1 to move client from protection group A to protection gropu B

Post by oleg.feoktistov »

Hi,

In that case the workflow would be the following:
1. Copy spec for a server from "Manually Added" protection group and add it to a custom one.
2. Rescan a changed protection group.
2. Re-add that same server to the existing jobs, but now from a custom protection group.
3. Remove that server from "Manually Added" protection group and rescan it.

On the last step remember not to remove the server inside "Manually Added" group from configuration instead - that server in both protection groups is the same one with one id, so it won't allow you to delete it as it has already been chosen as a source for a job from a custom protection group.

Please also note that a new backup chain will be started for the server that you re-added to a job.

Code sampe with one server migrated from "Manually Added" to a custom protection group while being added to one backup job:

Code: Select all

$manuallyPg = Get-VBRProtectionGroup -Name 'Manually Added'
$sourceCreds = $manuallyPg.Container.CustomCredentials | where {$_.HostName -eq 'local.server'}
$pcs = Get-VBRDiscoveredComputer -ProtectionGroup $manuallyPg
$sourcePc = $pcs | where {$_.Name -eq 'local.server'}
$targetPg = Get-VBRProtectionGroup -Name 'Protection Group 1'
$container = $targetPg.Container
$targetCreds = $container.CustomCredentials
$credsArray = @()
$credsArray += $targetCreds
$credsArray += $sourceCreds
$newContainer = Set-VBRIndividualComputerContainer -Container $container -CustomCredentials $credsArray
$targetPg = Set-VBRProtectionGroup -ProtectionGroup $targetPg -Container $newContainer
Start-Sleep -Seconds 5
Rescan-VBREntity -Entity $targetPg -Wait
$targetPc = Get-VBRDiscoveredComputer -ProtectionGroup $targetPg | where {$_.Name -eq 'local.server'}
$job = Get-VBRComputerBackupJob -Name 'Agent Backup Job 3'
$objects = $job.BackupObject
$newObjects = @()
foreach ($object in $objects) {
  if ($object.Id -ne $sourcePc.ParentId) {
     $newObjects += $object
  }
}
$newObjects += $targetPc
Set-VBRComputerBackupJob -Job $job -BackupObject $newObjects
Start-Sleep -Seconds 5
$newSourceArray = @()
$newSourceArray += $manuallyPg.Container.CustomCredentials | where {$_.HostName -ne 'local.server'}
$sourceContainer = Set-VBRIndividualComputerContainer -Container $manuallyPg.Container -CustomCredentials $newSourceArray
Set-VBRProtectionGroup -ProtectionGroup $manuallyPg -Container $sourceContainer
Start-Sleep -Seconds 5
Rescan-VBREntity -Entity $manuallyPg -Wait
Hope it helps,
Oleg
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests