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:
On Azure:
- 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!
Learn More
- 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
Featured Online Courses:
- AI Demystified: A 1-Hour Beginner’s Guide (Suitable for Non-Technical People)
- AI Essentials: A Beginner’s Guide to Artificial Intelligence
- Human-AI Synergy: Teams and Collaborative Intelligence
- SQL Server 2022: What’s New – New and Enhanced Features
- Working with Python on Windows and SQL Server Databases
- Introduction to Azure Database for MySQL
- Boost SQL Server Database Performance with In-Memory OLTP
- Introduction to Azure SQL Database for Beginners
- Essential SQL Server Administration Tips
- SQL Server Fundamentals – SQL Database for Beginners
- Essential SQL Server Development Tips for SQL Developers
- Introduction to Computer Programming for Beginners
- .NET Programming for Beginners – Windows Forms with C#
- SQL Server 2019: What’s New – New and Enhanced Features
- Entity Framework: Getting Started – Complete Beginners Guide
- Data Management for Beginners – Main Principles
- A Guide on How to Start and Monetize a Successful Blog
Check Also:
- How to Reset Your SQL Server Admin Password on Azure
- Comparison of SQL Server Deployment Options on the Azure Cloud Platform
- 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 the GnoelixiAI Hub newsletter on LinkedIn and stay up to date with the latest AI news and trends.
Subscribe to the SQLNetHub YouTube channel (SQLNetHub TV).
Subscribe to my personal YouTube channel.
Rate this article:
Reference: SQLNetHub.com (https://www.sqlnethub.com)
© SQLNetHub
Artemakis Artemiou, a distinguished Senior Database and Software Architect, brings over 20 years of expertise to the IT industry. A Certified Database, Cloud, and AI professional, he earned the Microsoft Data Platform MVP title for nine consecutive years (2009-2018). As the founder of SQLNetHub and GnoelixiAI Hub, Artemakis is dedicated to sharing his knowledge and democratizing education on various fields such as: Databases, Cloud, AI, and Software Development. His commitment to simplicity and knowledge sharing defines his impactful presence in the tech community.