Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dbajeremy opened this issue Nov 13, 2024 · 2 comments
Open

Comments

@dbajeremy
Copy link

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

@olahallengren
Copy link
Owner

@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

@dbajeremy
Copy link
Author

Email sent @olahallengren . Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants