Skip to main content

Powershell script to list all backups in a location

Tutorial

NOTE: There are a few assumptions with this script.

1 - There is an xml file created containing the credentials for a user that has access to the ASN server

    Example: Get-Credential | Export-CliXML - Path C:\Users\AcronisUser\Desktop\Credential.xml

2 - The path to the xml file and the location information in the acrocmd commands are modified with accurate information

3 - This script is run on the server with ASN installed

$username = $((Import-Clixml -Path <Drive_Letter:\Path\To\Credential.xml>).UserName)
$password = $((Import-Clixml -Path <Drive_Letter:\Path\To\Credential.xml>).GetNetworkCredential().Password)
$Archives = acrocmd list archives --loc bsp://<StorageNode_Server_Name>/<Vault_Name> --credentials=$username,$password --all --output=raw
$ArchiveArray = @()
ForEach ($Archive in $Archives)
    {
    If ($Archive -ne "The operation completed successfully.")
        {
        If ($Archive -ne "")
            {
            $objArchive = New-Object PSObject -Property @{
                Name = $(($Archive -split "`t")[0])
                Type = $(($Archive -split "`t")[1])
                Date_Created = $([DateTime]::ParseExact($(($Archive -split "`t")[2]),'dd.MM.yyyy HH:mm:ss',$null))
                Backed_Up_Device = $(($Archive -split "`t")[3])
                Owner = $(($Archive -split "`t")[4])
                Archive_Size = "$([Math]::Round(((($Archive -split "`t")[5]) / 1MB),2)) MB"
                Archive_Comments = $(($Archive -split "`t")[6])
                Password_Protected = $(($Archive -split "`t")[7])
                Data_Size = "$([Math]::Round(((($Archive -split "`t")[8]) / 1MB),2)) MB"
                }
            $ArchiveArray += $objArchive
            }
        }
    }
$BackupArray = @()
ForEach ($Archive in $ArchiveArray)
    {
    $Backups = acrocmd list backups --loc bsp://<StorageNode_Server_Name>/<Vault_Name> --credentials=$username,$password --arc=$($Archive.Name) --output=raw
    ForEach ($Backup in $Backups)
        {
        If ($Backup -ne "The operation completed successfully.")
            {
            If ($Backup -ne "")
                {
                $objBackup = New-Object PSObject -Property @{
                    Archive_Name = $($Archive.Name)
                    Archive_Type = $($Archive.Type)
                    Archive_Date_Created = $($Archive.Date_Created)
                    Backed_Up_Device = $($Archive.Backed_Up_Device)
                    Owner = $($Archive.Owner)
                    Archive_Size = $($Archive.Archive_Size)
                    Archive_Comments = $($Archive.Archive_Comments)
                    Archive_Password_Protected = $($Archive.Password_Protected)
                    Archive_Data_Size = $($Archive.Data_Size)
                    Backup_GUID = $(($Backup -split "`t")[0])
                    Backup_Type = $(($Backup -split "`t")[1])
                    Backup_Password_Protected = $(($Backup -split "`t")[2])
                    Backup_Date_Created = [DateTime]::ParseExact($(($Backup -split "`t")[3]),'dd.MM.yyyy HH:mm:ss',$null)
                    Backup_Data_Size = "$([Math]::Round((((($Backup -split "`t")[4]).Trim(' bytes') -replace ',','') / 1MB),2)) MB"
                    }
                $BackupArray += $objBackup
                }
            }
        }
    }
$BackupArray = $BackupArray | Select-Object -Property Backed_Up_Device,Archive_Name,Archive_Type,Archive_Date_Created,Archive_Size,Archive_Data_Size,Archive_Comments,Archive_Password_Protected,Owner,Backup_GUID,Backup_Type,Backup_Password_Protected,Backup_Date_Created,Backup_Data_Size | Sort-Object -Property Backed_Up_Device,Archive_Name,Backup_Date_Created

#Once all of the backups' information have been gathered, you can filter them by property value and perform actions against them.

#Example: Filter backups older than 30 days and delete them

#$FilteredBackups = $BackupArray | Where-Object {$_.Backup_Date_Created -le $(Get-Date).AddDays(-30)}

#ForEach ($Backup in $FilteredBackups)

#    {

#    acrocmd delete backup --loc bsp://<StorageNode_Server_Name>/<Vault_Name> --credentials=$username,$password --arc=$($Archive.Name) --backup=$($Backup.Backup_GUID)

#   }

0 Users found this helpful

Hi Thomas!

Nice script!

A few observations though

  • vaultpath and credential path could be refactored to a variable at the begining to ease configuring the script
  • You can execute this anywhere where acrocmd is available. Due to the supplied loc:bsp paramter, the execution is deferrred to asn service as the acrcmd documentation notes.
  • An advantage of the script is that as it relies on acrocmd it likely won't break across Acronis builds.
  • Though it works, it's terribly slow because the script is essentially doing an n+1 select.

I've made an SQL query that achives similar results (find it below), that is a lot faster, but can potentially break accross builds. Tested for SQL Server 14.0.1000 + Cyber Backup 12.5.14330

use acronis_vault_manager
go

select
    v.name as location_name,
    v.uri as location_path,
    a.name as archive_name,
    b.type as archive_type,
    CASE WHEN a.created = 0 THEN null else DATEADD(S, CONVERT(int,LEFT( a.created, 10)), '1970-01-01') end as archive_date_created,
    a.resource_name as backed_up_device,
    '' as owner,
    a.size as archive_size,
    a.description as archive_comments,
    a.protected_by_password as password_protected,
    a.data_size as data_size,
    b.backup_id,
    b.type as backup_type,
    CASE WHEN b.created = 0 THEN null else DATEADD(S, CONVERT(int,LEFT( b.created, 10)), '1970-01-01') end as backup_date_created,
    b.backed_up_data_size as backup_data_size
    from Backups b
join Archives a on b.archive_id = a.id
join Vaults v on a.vault_id = v.id
where a.deleted_time is null AND v.deleted_time is null AND location_name = <your location name>
order by backed_up_device, archive_name, backup_date_created
go

-- Peter