Script that delete all backups as pre-command of the execution of a specific plan
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
}

- Accedi per poter commentare