In a previous article, we discussed how you can create your first database on Azure SQL Database. In this article, we are going to see, how to backup a SQL Server database from on-premises to Azure blob storage. Moreover, we will see how we can restore a database on-premises, based on a backup file store on Azure blob storage.
High-level process to Backup a SQL Server Database from On-Premises to Azure Blob Storage
The high-level process to Backup a SQL Server Database from On-Premises to Azure blob storage is:
- If you haven’t created a generic storage account, you will need to create one (step 1).
- Check and take a note (step 2).
- Create a private blob container (step 3).
On SQL Server/SSMS On-Premises:
- Create a credential object that can access the storage account (step 4).
- Run the BACKUP database T-SQL statement (step 5).
- Verify that the backup file is on Azure Storage (step 6).
* To restore the database from Azure blob storage to the on-premises SQL Server instance, you just run the relevant RESTORE command.
Learn more about Azure SQL Database: Enroll to our Online Course!
Check our online course on Udemy titled “Introduction to Azure SQL Database for Beginners”
(special limited-time discount included in link).
Our course, will help you get started with Azure SQL Database and SQL Server on Azure Virtual Machines fast and easy. Many live demos included.
Step 1: Create a Generic Storage Account on Azure
The first step, is if you don’t have a generic Storage Account on Azure, to create one.
To do this, you navigate to “Storage Accounts” and click on the “Create storage account” button.
For the purposes of this demo, the account kind was set to “StorageV2”, that is “general purpose v2”.
Then, there is a validation process. As you can see in the below screenshot, validation was successful.
We then click on the “Create” button and after a few moments, we can see that the deployment was successfully completed.
Step 2: Check Access Keys
The next step, is to check the access keys. Take a note of key1 or key2, since they will be used later on-premises while defining the credential to be used for accessing the Azure storage account.
Step 3: Create Private Blog Container
The next step, is to create a private blob container. This container, will be used for storing the SQL Server database backup files.
Great! Now let’s switch to the on-premises SQL Server instance and follow the below steps.
Step 4: Create a Credential Object On-Premises (via SSMS)
We need to create a credential object, that will be allowing access to the previously created azure storage and private blob container.
See the below screenshot for more information on how I did it.
As you can see, in order to define the credential object, I used in the “SECRET” clause, the key provided in my Azure Storage account. Moreover, of course, I included the name of my Azure Storage account.
Step 5: Backup the On-Premises SQL Server Database to Azure (via SSMS)
Below, you can check out the sample database that I’m going to backup to Azure. The database is named “SampleDB” and it has a table named “tblTest” which has 3 records.
Here’s the BACKUP T-SQL statement:
As you can see, it is the normal BACKUP statement, with the only difference that I am using the “URL” clause along with specifying the credential I created earlier.
Backup was successful! Now the backup file is stored on my Azure Storage, in the blob container.
Step 6: Verify that the Backup File is on the Azure Storage
To verify that the backup file is on the Azure Storage, you can navigate to the blob container via the Storage Explorer. As you can see, the backup file is visible.
And here’s the properties of the backup file:
To Restore the Database from Azure Blob Storage to On-Premises
To restore the database from the Azure Blob Storage back to the on-premises SQL Server instance, you just use the RESTORE T-SQL statement along with using the “URL” clause and the credential object.
Last, if run again the SELECT statement just like we did before the backup, we can see that our data is there and available for use.
Learn More! Enroll to the Course!
Learn more about Azure SQL Database and get started fast and easy! Through our online course “Introduction to Azure SQL Database for Beginners“, you will get lifetime access to a comprehensive set of lectures and live demonstrations that will get you started with Azure SQL Database in no time! The course is regularly updated with additional educational material!
- Get started with Azure
- Tutorial: Design your first Azure SQL database using SSMS
- Create a storage account on Azure
- Back up SQL Server databases to Azure
Recommended Online Courses:
- Introduction to Azure SQL Database for Beginners
- SQL Server 2019: What’s New – New and Enhanced Features
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Administration Tips
- Boost SQL Server Database Performance with In-Memory OLTP
- Essential SQL Server Development Tips for SQL Developers
- Working with Python on Windows and SQL Server Databases
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- Introduction to SQL Server Machine Learning Services
- Entity Framework: Getting Started – Complete Beginners Guide
- How to Import and Export Data in SQL Server Databases
- Learn How to Install and Start Using SQL Server in 30 Mins
- A Guide on How to Start and Monetize a Successful Blog
- Learn Azure SQL Database: Creating your First Database
- How to Create an Azure SQL Server Virtual Machine
- What’s New in SQL Server 2019
Subscribe to our newsletter and stay up to date!
Check out our latest software releases!
Check out Artemakis’s eBooks!
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
Artemakis Artemiou is a Senior SQL Server Architect, Author, a 9 Times Microsoft Data Platform MVP (2009-2018). He has over 15 years of experience in the IT industry in various roles. Artemakis is the founder of SQLNetHub and TechHowTos.com. Artemakis is the creator of the well-known software tools Snippets Generator and DBA Security Advisor. Also, he is the author of many eBooks on SQL Server. Artemakis currently serves as the President of the Cyprus .NET User Group (CDNUG) and the International .NET Association Country Leader for Cyprus (INETA). Moreover, Artemakis teaches on Udemy, you can check his courses here.