/// <summary>
 /// Backups a site on-demand.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IWebSiteOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// Required. The name of the web space.
 /// </param>
 /// <param name='webSiteName'>
 /// Required. The name of the web site.
 /// </param>
 /// <param name='backupRequest'>
 /// Required. A backup specification.
 /// </param>
 /// <returns>
 /// The backup record created based on the backup request.
 /// </returns>
 public static WebSiteBackupResponse Backup(this IWebSiteOperations operations, string webSpaceName, string webSiteName, BackupRequest backupRequest)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IWebSiteOperations)s).BackupAsync(webSpaceName, webSiteName, backupRequest);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Updates a backup schedule for a site.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IWebSiteOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// Required. The name of the web space.
 /// </param>
 /// <param name='webSiteName'>
 /// Required. The name of the web site.
 /// </param>
 /// <param name='backupRequest'>
 /// Required. A backup schedule specification.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> UpdateBackupConfigurationAsync(this IWebSiteOperations operations, string webSpaceName, string webSiteName, BackupRequest backupRequest)
 {
     return operations.UpdateBackupConfigurationAsync(webSpaceName, webSiteName, backupRequest, CancellationToken.None);
 }
 /// <summary>
 /// Backups a site on-demand.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IWebSiteOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// Required. The name of the web space.
 /// </param>
 /// <param name='webSiteName'>
 /// Required. The name of the web site.
 /// </param>
 /// <param name='backupRequest'>
 /// Required. A backup specification.
 /// </param>
 /// <returns>
 /// The backup record created based on the backup request.
 /// </returns>
 public static Task<WebSiteBackupResponse> BackupAsync(this IWebSiteOperations operations, string webSpaceName, string webSiteName, BackupRequest backupRequest)
 {
     return operations.BackupAsync(webSpaceName, webSiteName, backupRequest, CancellationToken.None);
 }
        public void BackupSite()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(HttpPayload.BackupSite)
            };

            var handler = new RecordedDelegatingHandler(response) { StatusCodeToReturn = HttpStatusCode.OK };

            var client = GetWebSiteManagementClient(handler);

            BackupRequest backupRequest = new BackupRequest()
            {
                Name = "abc.zip",
                Databases = new List<DatabaseBackupSetting>(),
                StorageAccountUrl = "https://username.blob.core.windows.net/backup/?sv=2012-02-12"
            };
            backupRequest.Databases.Add(new DatabaseBackupSetting()
            {
                ConnectionString = "Server=someserver;Database=somedatabase;Uid=someusername;Pwd=somepassword;",
                DatabaseType = "MySql",
                Name = "db1"
            });

            var backupResponse = client.WebSites.Backup("space1", "baysite", backupRequest);
            Assert.Equal(HttpStatusCode.OK, backupResponse.StatusCode);

            var backupResult = backupResponse.BackupItem;
            Assert.Equal(backupResult.Status, BackupItemStatus.Created);
            Assert.Equal(1, backupResult.Databases.Count);

            Assert.Equal("abc.zip", backupResult.BlobName);
            Assert.Equal("abc.zip", backupResult.Name);
            Assert.Equal(0, backupResult.SizeInBytes);
            Assert.False(backupResult.Scheduled);
            Assert.True(backupResult.StorageAccountUrl.StartsWith("https://"));

            Assert.Equal("MySql", backupResult.Databases[0].DatabaseType);
            Assert.Equal("db1", backupResult.Databases[0].Name);
            Assert.True(!string.IsNullOrEmpty(backupResult.Databases[0].ConnectionString));
        }