How to backup a SQL database to an AZURE storage account using the Ola Hallengren scripts.
Requires the stored procedures from: https://ola.hallengren.com/sql-server-backup.html
First, create an azure storage account with block blob support (v2 will suffice) and then create a blob container within that. For this example we'll call it sqlbackup
.
Once created, generate an SAS token which allows full read/write access to the container and copy off the url. The url will have two parts and should look like this:
https://<storagename>.blob.core.windows.net/?sv=reallylongtokenstring
The next step is to store the SAS credentails in SQL Server so that it can be used by the backup command. To do this, open a query window on the master db and run the following sql (with <> substitutions):
IF NOT EXISTS
(SELECT * FROM sys.credentials
WHERE name = 'https://<storageaccount>.blob.core.windows.net/<containername>')
CREATE CREDENTIAL [https://<storageaccount>.blob.core.windows.net/<containername>]
WITH IDENTITY = 'SHARED ACCESS SIGNATURE',
SECRET = '<token string starting with sv>';
Create a new SQL Agent job which references the DatabaseBackup stored proc like so:
EXECUTE [dbo].[DatabaseBackup]
@Databases = 'USER_DATABASES',
@BackupType = 'FULL',
@Compress='Y',
@Url='https://<storageaccount>.blob.core.windows.net/<containername>',
@BlockSize=65536,
@MaxTransferSize=4194304
The key to this working is that the Url must match the SQL Server credential name created above.
Also, the BlockSize and MaxTransferSize settings are import for working with large dbs. See here for more guidance: https://blogs.msdn.microsoft.com/sqlcat/2017/03/10/backing-up-a-vldb-to-azure-blob-storage/
With that, the backups should start flowing!
Thanks for the post.
I have a question about the SQL Server backups retention on the Block blob storage:
Is there a way to set the retention using Ola's command?
I not what is the best way to set the retention on the Azure Block Blob Storage? In may case I want to set my backups to 16 days retention than delete them from the Blob Storage.
Thanks
Alan