Steps for Deploying Package to Azure Environment:
Step 1: Creating Storage Account
Before deploying the package to windows azure, we required to create Azure Storage service account for storing the Input XML and logging information files.
Input XML is used for informing the Worker Role about the list of databases with service name, user id, password for login to the database and where the backup files to be stored etc. There are two log files are used in the Worker Role, one is the Action Log and another is Error Log. These log files can be used for tracing what happened while doing these activities. So let’s first create a Storage Account.
Storage Account Name: tsqlazurebackup
Storage Access Key: ydGlhdyxrbK41hJTARbUprhLKXUS6ZmsMc1RazC94RDwq/LFlIaLsUXoNmOiQyiW+mIyn6TT0yiEomgw3cD9dw==
Storage Blob Container Name: sqlazurebackup
(Note: This information I used when publishing into my subscription for temporary purpose, this won’t work future)
Step 2: Updating Storage Account information in the configuration file
DefaultEndpointsProtocol=http;AccountName=<<StorageAccountName>>;AccountKey=<<PrimaryAccessKey>>
So for the Storage Account I created, the connection string would be
DefaultEndpointsProtocol=http;AccountName=tsqlazurebackup;AccountKey=ydGlhdyxrbK41hJTARbUprhLKXUS6ZmsMc1RazC94RDwq/LFlIaLsUXoNmOiQyiW+mIyn6TT0yiEomgw3cD9dw==
Below shows the DataConnectionString, InputXMLBlobConnectionString setting nodes –
<Setting name="DataConnectionString" value="DefaultEndpointsProtocol=http;AccountName=tsqlazurebackup;AccountKey=ydGlhdyxrbK41hJTARbUprhLKXUS6ZmsMc1RazC94RDwq/LFlIaLsUXoNmOiQyiW+mIyn6TT0yiEomgw3cD9dw==" />
<Setting name="InputXMLBlobConnectionString" value="DefaultEndpointsProtocol=http;AccountName=tsqlazurebackup;AccountKey=ydGlhdyxrbK41hJTARbUprhLKXUS6ZmsMc1RazC94RDwq/LFlIaLsUXoNmOiQyiW+mIyn6TT0yiEomgw3cD9dw==" />
<Setting name="InputXMLBlobContainerName" value="sqlazurebackup" />
Change the LogError to True to log error occurred while taking the backup and False not required.
<Setting name="LogError" value="True" />
The same applied to the action details also
<Setting name="LogAction" value="True" />
At the last my configuration file would as below
<?xml version="1.0" encoding="utf-8"?> <ServiceConfiguration serviceName="SQLAzureBackup" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="2" osVersion="*"> <Role name="WorkerRole"> <Instances count="1" /> <ConfigurationSettings> <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" /> <Setting name="DataConnectionString" value="DefaultEndpointsProtocol=https;AccountName=tsqlazurebackup;AccountKey=ydGlhdyxrbK41hJTARbUprhLKXUS6ZmsMc1RazC94RDwq/LFlIaLsUXoNmOiQyiW+mIyn6TT0yiEomgw3cD9dw==" /> <Setting name="LogError" value="True" /> <Setting name="LogAction" value="True" /> <Setting name="InputXMLBlobConnectionString" value="DefaultEndpointsProtocol=http;AccountName=tsqlazurebackup;AccountKey=ydGlhdyxrbK41hJTARbUprhLKXUS6ZmsMc1RazC94RDwq/LFlIaLsUXoNmOiQyiW+mIyn6TT0yiEomgw3cD9dw==" /> <Setting name="InputXMLBlobContainerName" value="sqlazurebackup" /> </ConfigurationSettings> </Role> </ServiceConfiguration>
Step 3: Changing the input XML
Input XML file is used for providing input to the worker role about the list of databases to take backup with login information and the place where the backup to be stored etc.
The database backup can be in two methods
Note: There is no link between the storage account specified in this Database node and the storage account specified in the ServiceConfiguration.Cloud.cscfg configuration file. The storage account configured in Database node will be used for storing database backup and the storage account configured in the ServiceConfiguration.Cloud.cscfg file used for storing the input XML file and logging files. So each database node can refer different storage account or can be same.
Below picture shows the XML structure for both of the backup methods
The attributes of Database node explained below.
You can have required attributes for the required backup you choose in the Database node. The following XML shows an example of my XML file which I used for testing on cloud.
<?xml version="1.0" encoding="utf-8"?> <Databases> <Database ServerName="j6gdqs61uk.database.windows.net" DatabaseName="Customers" UseWindowsAuth="false" LoginId="Thiru" Password="welcomedb@123" BackupFileName="Customers_@Date_@Time.bacpac" BackupScheduledPeriod="Daily" BackupScheduledTime="1:57 PM" LastBackupDateTime="08-Nov-2011 06:18 PM" ExportTo="Blob" ExportFileDirectory="D:\DatabaseBackup\@Date" TrustServerCertificate="false" UseSSL="false" BlobName="dbbackups" BlobContainerName="customerdb" BlobDefaultEndpointsProtocol="http" BlobAccessKey="h0/hPhKGH3UJJQf/YDRgmWpCK60ZaXCTvxgqG9JgEG459YXYVIeXZg5zqRIA4kOA7ybVBcZZuA5PDkeSyWO/4w=="></Database> </Databases>
Upload the XML file to the container of the storage account configured in the ServiceConfiguration.Cloud.cscfg. The worker role will start execution and when the server time meets the time mentioned in the XML file for any of the Database node with the date it will start the backup.
Currently the backup time will be considered as per the time running on the server instance. but I will work on this to standardize the timing for various zone. But as of now the backup schedule will be handled as below.
Say, we have required the backup to be done from tomorrow (01-June-2012) and the backup should be done by 12:00AM on daily basis. The values should be
BackupScheduledPeriod="Daily"
BackupScheduledTime="12:00 AM"
LastBackupDateTime="31-May-2012 12:00 AM"
When the worker role executing on 01-Jun-2012 at 12:00 AM, it will check whether the last backup date in XML equal to 31-May-2012 or less than that date. It will also check the backup scheduled time is 12 hours and minutes is less than compare to the current minute on the system. If this conditions are meet, the backup schedule will start and it will update the last backup date time to the current date time.
Upload the XML file to the blob container of the storage account configured and verify the backup file in the targeted location specified in the input XML.
More Information
The DAC whitepaper has a good overview of the DAC framework.
For more information about Import and Export on SQL Azure database can found in my blog (http://dotnettwitter.com/).
For any issues, please log into the Issue Tracker and please let me know if any change/enhancement with this tool. Love to know any positive and negative feedback…