Skip to content

Instantly share code, notes, and snippets.

@matejskubic
Created August 17, 2017 07:55
Show Gist options
  • Save matejskubic/c6fae79a36d583df7e8674296b8cb6cd to your computer and use it in GitHub Desktop.
Save matejskubic/c6fae79a36d583df7e8674296b8cb6cd to your computer and use it in GitHub Desktop.
Backup SQL DB to azure
DECLARE @dbToBackup as sysname = 'AxDB'
DECLARE @container as nvarchar(50) = lower(HOST_NAME())
DECLARE @file as nvarchar(100) = @dbToBackup + N'_' + FORMAT(GETDATE(), N'yyyy-MM-dd_hhmmss') + N'.bak'
DECLARE @destUrl as nvarchar(500) = N'https://storageaccount.blob.core.windows.net/' + @container + N'/' + @file
PRINT @destUrl
BACKUP DATABASE @dbToBackup TO
URL = @destUrl
WITH NOFORMAT, NOINIT, NAME = N'Ax-Full Database Backup', NOSKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10
GO
@matejskubic
Copy link
Author

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