In this article, we’ll walk through how to automate backups of multiple SQL Server databases directly to Azure Blob Storage using SQL Server Agent. This is ideal for hybrid or cloud-first architectures where backups must be offloaded to Azure for safe keeping.
Step 1: Create an Azure Blob Container & SAS Token
- Go to Azure Portal
- Navigate to your Storage Account → Containers
- Create a new container (e.g., )
- (Optional) If hierarchical namespace was enabled, you can create folders (year-wise, month-wise) inside.
- Generate a SAS token for the container with:
- Permissions: Write, List, Create, Add
- Expiry: Set it for a long duration (e.g., 1 year)
- Copy the Container URL and SAS token.
Step 2: Create a Credential in SQL Server
In SSMS, run the following T-SQL command. Replace the URL and Secret with yours.
Note: The SECRET must include the leading .
Step 3: Write the Backup Script
Run the following script to create stored procedure or just use it in the job step. It automates backup for all user databases.
This script:
- Loops through all non-system databases.
- Generates a unique filename with timestamp ().
- Backs up directly to the Azure Blob URL with compression.
Step 4: Create a SQL Server Agent Job
- Open SQL Server Management Studio (SSMS).
- Navigate to SQL Server Agent → New → Job...
- Name it (e.g., ).
- Steps Tab:
- Add a new step.
- Type: Transact-SQL.
- Database: .
- Paste the script from Step 3.
- Schedules Tab:
- Create a recurring schedule (e.g., Daily at 12 AM).
- Save the job.
Output Example
Once the job runs, you’ll see files in your Azure Blob container: