dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.39k stars 787 forks source link

Add support for SAS URL in Read-DbaBackupHeader and Get-DbaBackupInformation #9289

Closed david-garcia-garcia closed 3 months ago

david-garcia-garcia commented 3 months ago

Type of Change

New feature

Unless I am missing something, it is currently not possible to do database restores from a collection of backups stored in Azure Blobs (automatically). With the fixes in this PR I hope to be able to have restore automation to support the backups that can be made using Hallengren backup solution to Azure Blobs.

Purpose

Add support for Shared Access Singature URL's in Get-DbaBackupInformation and Read-DbaBackupHeader

Approach

Small tweaks to support URLS with SAS. See comments in code.

Commands to test

Read-DbaBackupHeader and Get-DbaBackupInformation

david-garcia-garcia commented 3 months ago

No need for any of this, you can extract the URL's manually and pass them in to Get-DbaBackupInformation

$ctx = New-AzStorageContext -StorageAccountName $backupUrl.storageAccountName -SasToken $backupUrl.sasToken;
$blobs = Get-AzStorageBlob -Container $backupUrl.container -Context $ctx -Prefix $backupUrl.prefix |
Where-Object { ($_.AccessTier -ne 'Archive') -and ($_.Length -gt 0) };

$blobUrls = $blobs | ForEach-Object { $backupUrl.baseUrl + $_.Name } 
$files = Get-DbaBackupInformation -SqlInstance $sqlInstance -Path $blobUrls | Where-Object { $_.Database -eq $databaseName };