PowerShell script exchange
Post Reply
maanlicht
Enthusiast
Posts: 32
Liked: 6 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

How to list and remove Orphaned replicas

Post by maanlicht »

Recently I successfully used a script to remove a list of VMs from a set of replication jobs because I believe the instant VM recovery feature is so fast that having a replica is no longer justified for some VMs. (Way the go Veeam!) The replicas however still show up under the ‘Replicas’ section.

I understand the ‘Remove-VBRReplica -FromDisk’ command can be used to clean them up. However the documentation tells me to use the ‘Get-VBRReplica’ command to make the initial selection of VMs. This is where I run into trouble. ‘Get-VBRReplica’ doesn’t seem to return the VM replicas as the documentation states. But instead returns the jobs they once belonged to. This makes it seemingly impossible for me to select the VMs I removed before since the job still exists and I don’t want to remove ALL replicas.

Since this is such a common function, my question to the community is: How do you guys list and remove Orphaned replicas with powershell?
jorgedlcruz
Veeam Software
Posts: 1560
Liked: 675 times
Joined: Jul 17, 2015 6:54 pm
Full Name: Jorge de la Cruz
Contact:

Re: How to list and remove Orphaned replicas

Post by jorgedlcruz »

Unfortunately, there's no direct way to get a list of orphaned VMs using Get-VBRReplica cmdlet, since it returns the list of replica jobs and not the individual VM replicas.

I have tried a few cmdlets and some commands, but nothing drove me far.

Will wait for others that maybe have achieved this with a bit of extra scipting.
Jorge de la Cruz
Senior Product Manager | Veeam ONE @ Veeam Software

@jorgedlcruz
https://www.jorgedelacruz.es / https://jorgedelacruz.uk
vExpert 2014-2025 / InfluxAce / Grafana Champion
oleg.feoktistov
Veeam Software
Posts: 2021
Liked: 673 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: How to list and remove Orphaned replicas

Post by oleg.feoktistov » 1 person likes this post

Hi,
‘Get-VBRReplica’ doesn’t seem to return the VM replicas as the documentation states. But instead returns the jobs they once belonged to.
That's not the case, Get-VBRReplica still returns replicas, not the jobs. The difference being is that in the UI we present replicas by VM names, whereas in powershell we present them by job names (true for VMware and Hyper-V replicas, vCD replicas are still presented by VM names). It happens because VMware and Hyper-V replicas don't have their own type in PS and are presented as CBackup. Hence, the schema for CBackup gets applied to these replica types as well. To see that these are, in fact, replicas, you can double check it through DB Manager classes:

Code: Select all

$replica = Get-VBRReplica
[Veeam.Backup.DBManager.CDBManager]::Instance.Replicas.GetReplicasFromBackup($replica[0].Id)
Orphaned replicas are the ones that have JobId property nulled. I'd also filter them by IsImported: $false since we are working with CBackup types here even though replicas cannot really be imported in a sense backups can be:

Code: Select all

$orphanedReplicas = Get-VBRReplica | where {$_.IsImported -eq $false -and $_.JobId -eq '00000000-0000-0000-0000-000000000000'}
$orphanedReplicas
Let me know if the output for the code I provided corresponds to your list of orphaned replicas.

Best regards,
Oleg
maanlicht
Enthusiast
Posts: 32
Liked: 6 times
Joined: Apr 05, 2023 1:06 pm
Full Name: maanlicht
Contact:

Re: How to list and remove Orphaned replicas

Post by maanlicht »

@oleg.feoktistov thankyou that is very helpful information and good to know about the DB Manager classes.
I tested nulled JobId trick in my lab but unfortunately it does not show orphaned VMs if the original job still exists and is in use. However after removing the job it indeed lists ALL the VMs as orphaned replicas. So it looks like the JobId only changes for an orphan if the parent job gets removed.
Do you know of any other way?
vvfpg
Lurker
Posts: 2
Liked: never
Joined: Nov 25, 2024 11:03 am
Full Name: vvfpg
Contact:

Re: How to list and remove Orphaned replicas

Post by vvfpg »

good morning, firt of all excuse me for my English.....I'm traying to delete a legacy replicas too, veeam r&D 12 setup is saying that i must delete a "Legacy replica VMs -Please remove the following replica VMs: targhe, but i can't find it and it stop me in the upgrade. My actual version is 11.0.1.1261. help me !!
david.domask
Veeam Software
Posts: 2679
Liked: 620 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: How to list and remove Orphaned replicas

Post by david.domask »

Hi vvfpg, welcome to the forums.

I would try Oleg's steps from above and see if anything is returned and just check the list. Once you get the replica in Powershell, you can then pass it to Remove-VBRReplica and it should clear it.

Similarly, you might check in the Replicas section of the UI (not Replicas > Ready, just click where it says "Replicas"), see if you spot it there.
David Domask | Product Management: Principal Analyst
vvfpg
Lurker
Posts: 2
Liked: never
Joined: Nov 25, 2024 11:03 am
Full Name: vvfpg
Contact:

Re: How to list and remove Orphaned replicas

Post by vvfpg »

so , here is the Oleg's comands:


1)
PS C:\Users\Administrator> $orphanedReplicas = Get-VBRReplica | where {$_.IsImported -eq $false -and $_.JobId -eq '00000000-0000-0000-0000-000000000000'}
PS C:\Users\Administrator> $orphanedReplicas

Job Name Type Creation Time VM count
-------- ---- ------------- --------
postced VMware Repli... 31/05/2019 12:29:51 1

2)
PS C:\Users\Administrator> $replica = Get-VBRReplica
>> [Veeam.Backup.DBManager.CDBManager]::Instance.Replicas.GetReplicasFromBackup($replica[0].Id)


Id : 2f31ce88-0ebd-4839-ba44-6204f683b458
BackupId : a1b29ee0-4fb7-4020-b8c0-1eaa31dd5bb9
ObjectId : 01ec2383-8dff-4733-878c-b3a14fe95893
VmName : VFPG-RDP3
SourceLocation : 172.16.100.8
TargetLocation : 172.16.100.3
TargetVmName : VFPG-RDP3_replica
TargetVmRef : 8
State : Ready
VpnConnectionState : NotSupported
IsPartialFailovered : False
ParentReplicaId :
IsSeedingInProcessing : False


there isn't a replica called "targhe"

3) and there isn't any replica called "targhe" in the Replicas section of the UI (not Replicas > Ready, just click where it says "Replicas"), see if you spot it there.

any suggestions ?

thank you Guys !!!
Post Reply

Who is online

Users browsing this forum: No registered users and 63 guests