Skip to main content

Script that delete all backups as pre-command of the execution of a specific plan

Thread needs solution
Beginner
Posts: 2
Comments: 3

Hello,

I'm trying to build a script that delete all backups from a specific vault before each execution of a specific plan.

My goal it's only do full backup on a fresh vault every week days.

So my script work partially. It only delete few archives and not all of them.

Can someone help me with this.

See the the script below without authentication to the platform : 

$Locations = Invoke-RestMethod -Method "GET" -Uri "${baseUrl}bc/api/vault_manager/v1/vaults?count=1&includeStats=true&limit=30&order=asc(name)" -Headers $headers -ContentType "application/json"

$Location = $Locations.items | Select-Object {$_.uri}, {$_.id}, {$_.managing_agent_id} | where {$_.uri} -like "*usbshare1*"

$VaultId = $Location.'$_.id'
$MachineId = $Location.'$_.managing_agent_id'

$Archives = Invoke-RestMethod -Method "GET" -Uri "${baseUrl}bc/api/vault_manager/v1/vaults/$VaultId/archives" -Headers $headers -ContentType "application/json"

$ArchivesId = $Archives.items | Select-Object {$_.legacy_id}

foreach ($ArchiveId in $ArchivesId) {

$ArchiveId = $ArchiveId.'$_.legacy_id'

$ArchiveId = [System.Web.HttpUtility]::UrlEncode("$ArchiveID")

$Archives = Invoke-RestMethod -Method "DELETE" -Uri "${baseUrl}bc/api/ams/archives/%3CpatharchiveId%3E?archiveId=$ArchiveID&machineId=$MachineId" -Headers $headers -ContentType "application/json" -Body $paramarchives

}
 

0 Users found this helpful
Support specialist
Posts: 0
Comments: 1456

#1

Hello Adrien,

thank you for posting on Acronis forums!

My goal it's only do full backup on a fresh vault every week days.

We can't recommend this scheme because you are at risk to be without a backup if for some reason a new backup will fail. We advise that you select Always full backup scheme and set retention (cleanup) rules By number of backups (e.g. 1 as in your case) and set a cleanup task to be performed After backup so you will always have a copy of a full backup even if a failure occurs.

So my script work partially. It only delete few archives and not all of them.

If a backup you want to delete has dependencies, it will be consolidated or marked for deletion until all dependent backups become subject to deletion.

Yiu also can