PowerShell script exchange
Post Reply
Eson
Service Provider
Posts: 18
Liked: never
Joined: May 30, 2013 2:20 pm
Full Name: Emanuel Gustavsson
Contact:

Delete Replicas from disk that are older than x days

Post by Eson »

When a VM is deleted from our Hyper-V environment and stops being backed up it will still stay as a replica. Thats fine but I want to automate that replicas that are older than for example 7 days should be deleted and removed from disk.

I have experimented with Get-VBRRestorepoint and Get-VBRReplica/Remove-VBRReplica but havent been able to get a working script. Anyone have a suggestion for solving this? How would I make a selection from get-vbrreplica based on creation time?
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Delete Replicas from disk that are older than x days

Post by david.domask »

Hi Emanuel,

I think probably you will want to first collect your Replicas with Get-VBRReplica and then loop over the returned results and check the LastPointCreationTime property; that will tell you the most recent restore point and should help you identify which replicas are no longer relevant.

I would suggest though to check and confirm the replica schedule somehow in your script as well as maybe do a check with Find-VBRHvEntity to see if the replica in question, however this is done per-job, so I'm not sure that it will work for you directly since Remove-VBRReplica will act on the object returned by Get-VBRReplica, which includes all VMs in the replica job. If you are doing a single VM per replica job, then this will work, but else I'm not sure that Powershell can be used for your needs right now.
David Domask | Product Management: Principal Analyst
Eson
Service Provider
Posts: 18
Liked: never
Joined: May 30, 2013 2:20 pm
Full Name: Emanuel Gustavsson
Contact:

Re: Delete Replicas from disk that are older than x days

Post by Eson »

Thanks David for the earlier reply, havent had any success with this.

Even if we limit our scope and dont care about the age aspect and just wanted to delete a specific replica through powershell. I cant find any way to do this either. Remove-VBRReplica only acceptes the cbackup object of and actual replica job. Even if you can list each replica whithin a job with Veeam.Backup.DBManager.CDBManager you cant take any action on this data and delete a single replica. Or have I missed something?
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Delete Replicas from disk that are older than x days

Post by david.domask »

Hi Emanuel,

You're very welcome, but my apologies, I forgot to mention an important step. As noted on the Remove-VBRReplica cmdlet page, for individual replicas, you need to use Remove-VBRRestorePoint.

From the Remove-VBRReplica Page: https://helpcenter.veeam.com/docs/backu ... ml?ver=120
This cmdlet removes all VMs in the replication job. To remove individual VMs, run the Remove-VBRRestorePoint cmdlet.
So similar process, just fetch the replica restore point. An easy way to filter between Backups and Replica with Get-VBRRestorePoint is to pipe to Where-Object and filter on the Type property where Type -eq "Snapshot". For example:

Get-VBRRestorePoint | Where-Object {$_.Type -eq "Snapshot"}

That would filter all the results returned by Get-VBRRestorePoint, but you can of course do further filtering on VmName.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests