Skip to content

Instantly share code, notes, and snippets.

@joshtwist
Created January 20, 2013 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshtwist/4579940 to your computer and use it in GitHub Desktop.
Save joshtwist/4579940 to your computer and use it in GitHub Desktop.
Backup your SQL Database using Mobile Services' scheduler
function backup() {
var request = require('request');
var util = require('util');
var date = new Date();
var year = date.getUTCFullYear();
var month = date.getUTCMonth() + 1;
var day = date.getUTCDate();
var body = {
BlobCredentials : {
__type : "BlobStorageAccessKeyCredentials:#Microsoft.SqlServer.Management.Dac.ServiceTypes",
Uri : util.format("https://<your-storage-account-name>.blob.core.windows.net/bacpac/%s-%s-%s.bacpac", year, month, day),
StorageAccessKey : "your-storage-access-key"
},
ConnectionInfo: {
DatabaseName : "<your-database-name>",
Password : "<your-server-password>",
ServerName : "<your-server-name>.database.windows.net",
UserName : "<your-server-username>"
}
}
/* endpoint depends on the Datacenter of the DB
North Central US https://ch1prod-dacsvc.azure.com/DACWebService.svc
South Central US https://sn1prod-dacsvc.azure.com/DACWebService.svc
North Europe https://db3prod-dacsvc.azure.com/DACWebService.svc
West Europe https://am1prod-dacsvc.azure.com/DACWebService.svc
East Asia https://hkgprod-dacsvc.azure.com/DACWebService.svc
Southeast Asia https://sg1prod-dacsvc.azure.com/DACWebService.svc
East US https://bl2prod-dacsvc.azure.com/DACWebService.svc
West US https://by1prod-dacsvc.azure.com/DACWebService.svc
*/
var postUri = "https://bl2prod-dacsvc.azure.com/DACWebService.svc/Export";
request.post({
uri: postUri,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body)
}, function(e, r, b) {
if (e || r.statusCode != 200) {
console.error('backup failed', e || r.statusCode, b);
}
else {
console.log('backup successful', b);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment