See https://learn.microsoft.com/en-us/sql/relational-databases/tutorial-sql-server-backup-and-restore-to-azure-blob-storage-service?view=sql-server-ver16&tabs=SSMS for a step-by-step tutorial to backup to Azure Blob Storage. Note, in every GUI step you have the option to generate a SQL Script, which you can use in your job.
SQL Server: Creating a Job to backup to my Azure container/blob
I was able to create a Backup on to Azure through the Task and the Run the Backup. The problem that am having its that when I create a job to schedule a backup I get this error: Date 4/19/2023 4:12:08 PM Log SQL Server (Current - 4/20/2023 9:45:00 AM) Source spid90 Message BackupVirtualDeviceFile::DetermineFileSize: SetPosition(0,EOF) failure on backup device 'https://sqlb.blob.core.windows.net/sqlbbackup_nsft_20230419.bak'. Operating system error Backup to URL received an exception from the remote endpoint. Exception Message: The remote server returned an error: (404) Not Found..
This is the current query that am using in the steps to create the job:
DECLARE @DBName NVARCHAR(255)
DECLARE @BackupPath NVARCHAR(1024)
DECLARE @BackupFileName NVARCHAR(1024)
-- Set the backup path to your Azure Storage container
SET @BackupPath =
-- Loop through each database on your server
DECLARE db_cursor CURSOR FOR
SELECT name FROM sys.databases
WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb') -- Exclude system databases
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @DBName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @BackupFileName = @DBName + '_' + REPLACE(CONVERT(NVARCHAR(50), GETDATE(), 120), ':', '') + '.bak'
-- Perform the backup
BACKUP DATABASE @DBName
TO URL = @BackupPath + @BackupFileName
WITH CREDENTIAL = 'azure',
COMPRESSION, STATS = 10
FETCH NEXT FROM db_cursor INTO @DBName
END
CLOSE db_cursor
DEALLOCATE db_cursor
Azure SQL Database
Azure Storage
2 answers
Sort by: Most helpful
-
-
Alberto Morillo 34,671 Reputation points MVP Volunteer Moderator
2023-04-20T16:43:30.1066667+00:00 Please make sure the storage account is of type General Purpose.