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!
Hi Abdallah.
Looks like this is defaulted to NULL already in the sproc definition so you shouldn't need to specify that when calling - https://github.com/olahallengren/sql-server-maintenance-solution/blob/588c16545cdb59432489f73695fbb7f6d0161112/DatabaseBackup.sql#L42