Best practice to upgrade a SQL Azure DB? - azure

I am trying to upgrade an Azure DB in a continuous release scenario. The DB lives in SQL Azure and its size keeps growing. Now it's about > 50G. In my previous on-premise experience, I usually backup the old DB in a compressed format and save it to an on-premise file sever. In case the upgrade fail, I can restore it safely.
But with SQL Azure, I am not sure if it's OK to download such a big DB from SQL Azure. And is there any best practice for the SQL Azure DB upgrade scenario?
ADD
I found this link regarding different SQL Azure backup strategies. But it'll be great if someone can share some field experiences.

Azure now has automatic exports (aka full backups) to blob storage that you can schedule. The .bacpac files are complete compressed copies of your database and blob storage is pretty cheap. To give you an idea of size we have a 20GB database that is backed up to only 500 MB. We typically keep 14 days of backups but how long to retain them is up to your needs.
It's kind of like the Ron Popeil Rotisserie. You just set it, and forget it.
Obviously after you take a backup you want to restore it somewhere else to verify it worked. It's also a good idea to periodically restore your backups to make sure they working over time. You can do all of this in the Azure Portal. Just create a new database based on a .bacpac file that you created from the automated export.
You actually don't have to download the DB on premise unless you want another copy locally. Because if you are using geo-redundant blob storage its already copied to another region and you have 6 copies in total. But again its up to you.
When you log into the management portal navigate to the Sql Database tab. Click on your DB and then click configure. There you can set up automated backups for your db to blob storage.
The path on the management portal looks like this:
https://manage.windowsazure.com/mycompany.com#Workspaces/SqlAzureExtension/SqlServer/coolazuredb/Database/5.coolazuredb/Config
Here is a screenshot of the automated export section:

Related

Challenges with Azure SQL Managed Instance

Unable to make a copy of the database using the following SQL command or through the Azure portal
CREATE DATABASE mydatabase_copy AS COPY OF mydatabase;
Unable to make a copy of the database on Azure SQL Server, no wizard is present
we know there is a way of creating bacpac and restoring it, but this is a complete manual process and take too much time
we need some automated way to achieve this.
CREATE DATABASE ... AS COPY OF is not available in Managed Instance, only in SQL Database. Instead use Point-in-time restore
Use point-in-time restore (PITR) to create a database as a copy of
another database from some time in the past. This article describes
how to do a point-in-time restore of a database in Azure SQL Managed
Instance.
Point-in-time restore is useful in recovery scenarios, such as
incidents caused by errors, incorrectly loaded data, or deletion of
crucial data. You can also use it simply for testing or auditing.
Backup files are kept for 7 to 35 days, depending on your database
settings.
Which you can automate with PowerShell.

Restore to Azure SQL PAAS database a bak file?

Okay so I figured since Azure has a lot of tools and I am failing at best processes to just ask on SO.
What I can do:
BACPAC creation
Creation is directly from SSMS with hovering over the database in Object Explorer. Right Click>Tasks>Export Data Tier Application. Choose a disk location. The caveat is generally to not have a database that is in use querying. So have a copy or system that can be not using the database.
BACPAC restore to Azure
SqlPackage.exe https://learn.microsoft.com/en-us/sql/tools/sqlpackage?view=sql-server-2017
When I do it it is similar to: (must have Visual Studio or equivalent Sql management object DLLs installed)
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130\SqlPackage.exe" /a:Import /sf:(bacpac Location) /tdn:(dbName)/tsn:bvtest.database.windows.net /tu:(user) /tp:(password)
In Azure>SQL Servers>(Top ribbon)>Import database>(have blob storage with a bacpac created to it already). This method appears slightly faster if they are both on same region.
My question is that I have seen articles like this one: https://learn.microsoft.com/en-us/sql/azure-data-studio/tutorial-backup-restore-sql-server?view=sql-server-2017 as well as knowing SSMS pretty well. It seems all options to restore to Azure SQL PAAS are turned off for a 'bak' backup and you have to make a bacpac for going instance to Azure PAAS. The problem is that this takes hours just to make the bacpac on a relatively medium sized database of 120 gigs. Then it takes hours to restore. Other than what I have tried above is there a faster way?
You can use Azure Data Migration Service (ADMS) instead of importing/exporting bacpacs. Azure Data Migration Service allows you to migrate data from SQL Server to Azure SQL Database with no downtime if your database does not have "heaps". If your database has heaps you will have to perform an offline migration. Copying/migrating data from a SQL Server ARM (IaaS) Premium Storage (200 GB / 790 tables) to an Azure SQL Database (Premium) takes 1 hour 40 minutes with an offline migration. That is the fastest data migration I have seen as a workaround to import/export bacpacs since SQL Server native backups are not supported on Azure SQL Database (DTU-model / Vcore model).
ADMS performs a validation of your data at the end, if you want.

Cannot see long-term backup files for Azure SQL

If I select to restore my Azure SQL database, I can choose from a large number of long-term backup files.
However, I just want to download those files locally.
I cannot see where I can access these files.
The Azure docs suggest that I click on the 'Manage Backups' link.
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-long-term-backup-retention-configure
I cannot see this link though.
Has anyone any idea where I can access these files?
You cannot restore those backup files to a local computer because this is a service managed by Azure.
What you can do is restore to a point-in-time which will create a new database, then export that database as bacpac to your local computer, and remove the newly created database once is no longer needed.
SqlPackage /Action:Export /SourceServerName:SampleSQLServer.sample.net,1433 /SourceDatabaseName:RestoredDatabase /TargetFile:"F:\Temp\RestoredDatabase.bacpac"

How to export DB of a specific time?

I want to check how was my data 2 days ago and to do that I though of exporting a back up that Azure take every hour. But I cannot find it.
I've found this page on Microsoft that talks about exporting a DB but it is for the current data.
Azure SQL Database automatically creates database backups and writes them to read-access geo-redundant storage (RA-GRS) for geo-redundancy. Frequency depends on what kind of load the service is dealing with, duration backups are kept depends on the tier you've purchased.
To recover to a point in time using the Azure portal, open the page for your database and click Restore on the toolbar.
You cannot overwrite an existing database during restore, so you need to create a new instance for the point-in-time restore, and you'll pay for that. You can also do the restores programmatically using PowerShell.
Further details here.
I suggest to execute a restore, with a specific time, on a temporary DB then export it to a bacpac file. You can use Azure CLI for that:
az sql db restore with -time option for restoring
az sql db export for exporting
az sql db delete for deleting the temporary database
https://learn.microsoft.com/en-us/cli/azure/sql/db
The same can be also achieved using Azure Portal.

How to backup Azure SQL that will withstand deletion of azure server

Azure SQL has built in backups. If the SQL database and server are deleted from within the Portal these backups are lost.
What is best practice for backing up Azure SQL that will withstand deletion of the server from the portal.
I have manually exported the database to a storage location, however Azure says that this should not be used as a backup. Why should it not be used and what should I be doing instead?
If you want a direct control over your backups, then the best mechanism is fairly straight forward.
Create a copy of your database. This ensures no active transactions because it's a copy.
Use the BACPAC process to export the copy of the database. BACPAC doesn't respect transactions, this is why we created a copy.
Store this where ever you want.
Drop the copy of the database because you're paying for that while it exists.
You can use the BACPAC to import into a new Azure database, or you can import it into a VM in Azure, AWS, or locally.
Azure SQL has built in backups. If the SQL database and server are
deleted from within the Portal these backups are lost.
Yes,If you delete the Azure SQL server that hosts SQL Databases, all databases that belong to the server are also deleted and cannot be recovered. You cannot restore a deleted server.
What is best practice for backing up Azure SQL that will withstand
deletion of the server from the portal.
If your Azure SQL Server has been deleted, you need to create a support ticket to restore the databases.
When you really need to delete a SQL sever and then try to back up it, You can configure the Azure Recovery Services vault to store Azure SQL database backups and then recover a database using backups retained in the vault using the Azure portal or PowerShell.
Why should it not be used and what should I be doing instead?
I think you can export your database to your local storage , but it's complex to restore it to Azure. Also, it may change some information of your SQL database and may need migration to Azure.
Well, there is no real answer to this, you can use any backup method you like. Its mostly a personal preference.
But the easiest way (probably) is using Azure Backup Vault to do long term backups (which is a native way for Azure). Its pretty easy to configure (next\next\next) and it is not connected to the Azure SQL Server, so when you delete the server the backups are there.

Resources