Windows Azure SQL Database Backup and Restore
Backing up and restoring data is different in Windows Azure SQL Database than an on-premise SQL Server and must work with the available resources and tools. This topic introduces the concepts and the functionality available currently to back up and restore the data within Windows Azure SQL Database.
Database backups protect the database against data loss caused by hardware failures, user, or application errors or a widespread loss of regional facilities. Windows Azure has built-in fault tolerance to protect your data from individual server, network, and device failures. For more information about the built-in fault tolerance and replication internals, see this blog post. For business continuity concepts and in-depth information, see Business Continuity in Windows Azure SQL Database.
In order to protect your data against user/application errors or a total loss of a region you must create your own backup of the data. The following are the options that are available to you to create a backup of the data and schema:
-
Create a Copy of the source database using Database Copy
-
Create a logical backup (BACPAC) file using SQL Database Import/Export Service
-
Create a logical backup (BACPAC) file using SQL Server Management Studio
Tip |
|---|
| There are several ways to create a BACPAC file, this topic covers using the Import/Export Service and SQL Server Management Studio. Some other options include using the DacFX API, Import/Export client, and using the Import/Export REST endpoints. For more details, see Automating Windows Azure SQL Database Backup. |
The following sections describe the options in more detail:
Create a copy of the source database Windows Azure SQL Database using Database Copy
Creating a copy:
The database copy feature creates a new database, which is a copy of the source SQL Database. The new database is transactionally consistent with the source database at the time when the copy process is completed. What this means is that when the copy process is in progress, all changes to the source are replicated to the copy. The copy can be used in the rollback plan for changes to schema or data, and unwanted deletion or modification. Creating a copy provides protection against user or application errors.
Using T-SQL statements you can create a copy of the source database, on the same or different Windows Azure SQL Database server. From a database backup perspective, copying the database on a recurring schedule is like taking full backups of an on-premise SQL Server database. By copying a database on a recurring schedule, you can create copies on a daily schedule or a schedule that fits your data recovery plan.
Following is a simple T-SQL example to create a copy of the source database:
CREATE DATABASE destination_database_name AS COPY OF [source_server_name].source_database_name
The following are some important considerations when you use database copy:
-
Database copies can be created on the same or different Windows Azure SQL Database server, but the server must be in the same region.
-
Database copies are charged at the same rate as the source database when the copy is complete and are counted towards the 150 databases per server limit.
For detailed step by step instructions for copying a SQL Database, see How to: Copy Your Databases (Windows Azure SQL Database).
For other considerations and details, see How to help protect your database from unwanted deletions or modifications.
Restoring the data and schema:
When the copy is on the same server as the source database, to restore, you can rename the copy to that of the source database. If the copy is on a different server, you can point your application to the copy. The following code example illustrates renaming the source and copy on the same server:
ALTER DATABASE Database1 MODIFY NAME = Database1_OLD GO WAITFOR DELAY '00:00:30' GO ALTER DATABASE Database1_copy_02_01_2012 MODIFY NAME = Database1 GO
The WAITFOR DELAY is included in the statement to make sure that new connections formed during this process do not accidentally connect to the old database before the renaming is completed. For more details, see the Database Copy Restore section in How to help protect your database from unwanted deletions or modifications.
Create a logical backup (BACPAC) file using SQL database Import/Export Service
Export data and schema to a BACPAC file:
The SQL Database Import Export Service copies the object definitions and data from the source Windows Azure SQL Database to a logical export file (BACPAC). This operation is then followed by a bulk copy of the data from the user tables to the BACPAC file. To make sure that you have an isolated copy of the data which is transactionally consistent, you must first create a database copy, and then create the BACPAC file from the copy. Alternatively, you can also prevent modifications to the data in the databases during export by limiting access to the databases through permissions or connections. Use the following steps to create a backup of the SQL Database.
To export a BACPAC file
-
Create a copy of the source database using Database Copy described in the previous section.
-
Export a BACPAC file to Windows Azure storage using the Windows Azure Portal. The BLOB storage account should be in the same region as the SQL Database to avoid datacenter data transfer charges.
-
Copy the file from BLOB to a local storage. This is an optional step that you can use to create an offsite backup.
-
Verify your backup by importing the BACPAC file which creates a new database on Windows Azure or to an on- premise instance of SQL Server.
-
After you have verified the BACPAC file, you may delete the copied database if you want.
For detailed step by step instructions on how to export a database, see Export a Database.
Restoring the Windows Azure SQL Database data and schema:
Using the SQL Database Import/Export Service, import a BACPAC file to create a new database. Point your application to the new database. Or alternatively, you can rename the source and the new database.
For step by step instructions on how to import a database, see Import a Database.
Create a logical backup (BACPAC) file using SQL Server Management Studio
This is similar to the process described in the SQL Database Import/Export service section, but the BACPAC file is created by using SSMS.
Create a backup:
To export a BACPAC file
-
Connect to the Windows Azure SQL Database server from SSMS. Connecting to a Windows Azure SQL Database from SSMS requires specific firewall settings and connection strings. For more details, see Managing Windows Azure SQL Database using SQL Server Management Studio.
-
Create a copy of the source database using Database Copy described in the database copy section.
-
Using the Export Data-tier Application task, export a BACPAC file to a local disk or a Windows Azure storage account.
-
Verify your backup by importing the BACPAC file which creates a new database on Windows Azure or to an on-premise instance of SQL Server.
For step by step instructions, see Export a Data-tier Application
Restoring the Windows Azure SQL Database data and schema:
Using the Import Data-tier Application task, import a BACPAC file to create a new database. Point your application to the new database. Or alternatively, you can rename the source and the new database. For step by step instructions, see Import a BACPAC file to Create a New Database.
See Also
Tip