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!
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.
Check the data after the restore operation.
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!
(Lifetime Access/ Live Demos / Downloadable Resources and more!)
Artemakis Artemiou is a seasoned Senior Database and AI/Automation Architect with over 20 years of expertise in the IT industry. As a Certified Database, Cloud, and AI professional, he has been recognized as a thought leader, earning the prestigious Microsoft Data Platform MVP title for nine consecutive years (2009-2018). Driven by a passion for simplifying complex topics, Artemakis shares his expertise through articles, online courses, and speaking engagements. He empowers professionals around the globe to excel in Databases, Cloud, AI, Automation, and Software Development. Committed to innovation and education, Artemakis strives to make technology accessible and impactful for everyone.
Views:11,785
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Read More
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.