olahallengren/sql-server-maintenance-solution

Add support for writing a SQL backup to Azure Blob Storage with SQL Safe

Opened this issue · 2 comments

Hi @olahallengren , we spoke at the recent PASS Data Summit in Seattle. You asked me to open a feature request which is to add the ability to use SQL Safe to write a backup to Azure Blob Storage which is not currently supported with your backup stored procedure. Here's documentation on how to do it from Idera using T-SQL:

/*
Important Notes:

  1. SQL Safe Backup: Ensure that SQL Safe Backup is properly installed and configured in your SQL Server environment.
  2. Azure Credentials: Use the correct Azure Storage account name and access key.
  3. Container: Make sure the specified blob container exists in your Azure Storage account.
  4. Permissions: Ensure that the SQL Server service account has the necessary permissions to access Azure Blob Storage.
  5. Error Handling: This script provides basic error handling. You may want to enhance it depending on your requirements.
    */

-- Step 1: Set up Azure Blob Storage Credentials
-- Replace with your actual Azure Storage account name and key
DECLARE @StorageAccountName NVARCHAR(100) = 'your_storage_account_name';
DECLARE @StorageAccountKey NVARCHAR(100) = 'your_storage_account_key';
DECLARE @ContainerName NVARCHAR(100) = 'your_container_name';

-- Step 2: Define the database and backup parameters
DECLARE @DatabaseName NVARCHAR(100) = 'YourDatabaseName';
DECLARE @BackupFileName NVARCHAR(255);
DECLARE @BackupFilePath NVARCHAR(4000);

-- Generate the backup file name with a timestamp
SET @BackupFileName = @DatabaseName + '_' + FORMAT(GETDATE(), 'yyyyMMdd_HHmmss') + '.bak';

-- Specify the backup path in Azure Blob Storage
SET @BackupFilePath = 'https://' + @StorageAccountName + '.blob.core.windows.net/' + @ContainerName + '/' + @BackupFileName;

-- Step 3: Execute the backup command
EXECUTE [dbo].[xp_ss_backup]
@DatabaseName = @DatabaseName,
@BackupType = 'FULL', -- or 'DIFF' for differential backups
@BackupFilePath = @BackupFilePath,
@StorageAccountName = @StorageAccountName,
@StorageAccountKey = @StorageAccountKey,
@Compression = 1, -- 1 for compression, 0 for no compression
@encryption = 0; -- 1 for encryption, 0 for no encryption

-- Step 4: Check for success
IF @@error = 0
BEGIN
PRINT 'Backup completed successfully.';
END
ELSE
BEGIN
PRINT 'Backup failed. Please check the logs.';
END

@dbajeremy, thank you for creating the issue. I had one additional thing that I would like to discuss. Could you send me an email?
https://ola.hallengren.com/contact.html

Email sent @olahallengren . Thanks!