/// <summary> /// Performs the call to import database using the server data service context channel. /// </summary> /// <param name="serverName">The name of the server to connect to.</param> /// <param name="input">The <see cref="ImportInput"/> object that contains /// all the connection information</param> /// <returns>The result of the import request. Upon success the <see cref="ImportExportRequest"/> /// for the request</returns> internal ImportExportRequest ImportSqlAzureDatabaseProcess(string serverName, ImportInput input) { ImportExportRequest result = null; try { XmlElement requestId = RetryCall(subscription => this.Channel.ImportDatabase(subscription, serverName, input)); Microsoft.WindowsAzure.ServiceManagement.Operation operation = WaitForSqlDatabaseOperation(); if (requestId != null) { result = new ImportExportRequest(); result.RequestGuid = requestId.InnerText; } } catch (Exception ex) { SqlDatabaseExceptionHandler.WriteErrorDetails( this, this.SqlConnectionContext.ClientRequestId, ex); } return(result); }
/// <summary> /// Process the import request /// </summary> public override void ExecuteCmdlet() { try { // Obtain the Blob Uri and Access Key string blobUri = null; string accessKey = null; switch (this.ParameterSetName) { case ByContainerNameParameterSet: accessKey = System.Convert.ToBase64String( this.StorageContext.GetCloudStorageAccount().Credentials.ExportKey()); blobUri = this.StorageContext.BlobEndPoint + this.StorageContainerName + "/" + this.BlobName; break; case ByContainerObjectParameterSet: accessKey = System.Convert.ToBase64String( this.StorageContainer.CloudBlobContainer.ServiceClient.Credentials.ExportKey()); blobUri = this.StorageContainer.Context.BlobEndPoint + this.StorageContainer.Name + "/" + this.BlobName; break; default: throw new NotSupportedException("ParameterSet"); } // Retrieve the fully qualified server name string fullyQualifiedServerName = this.SqlConnectionContext.ServerName + Profile.Context.Environment.GetEndpoint(AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix); // Issue the request ImportExportRequest context = this.ImportSqlAzureDatabaseProcess( this.SqlConnectionContext.ServerName, new Uri(blobUri), accessKey, fullyQualifiedServerName, this.DatabaseName, this.MyInvocation.BoundParameters.ContainsKey("Edition") ? this.Edition.ToString() : null, this.MyInvocation.BoundParameters.ContainsKey("DatabaseMaxSize") ? this.DatabaseMaxSize : 0, this.SqlConnectionContext.SqlCredentials); this.WriteObject(context); } catch (Exception ex) { this.WriteErrorDetails(ex); } }
/// <summary> /// Process the export request /// </summary> protected override void ProcessRecord() { try { base.ProcessRecord(); // Obtain the Blob Uri and Access Key string blobUri = null; string accessKey = null; switch (this.ParameterSetName) { case ByContainerNameParameterSet: accessKey = Convert.ToBase64String( this.StorageContext.StorageAccount.Credentials.ExportKey()); blobUri = this.StorageContext.BlobEndPoint + this.StorageContainerName + "/" + this.BlobName; break; case ByContainerObjectParameterSet: accessKey = Convert.ToBase64String( this.StorageContainer.CloudBlobContainer.ServiceClient.Credentials.ExportKey()); blobUri = this.StorageContainer.Context.BlobEndPoint + this.StorageContainer.Name + "/" + this.BlobName; break; default: throw new NotSupportedException("ParameterSet"); } // Retrieve the fully qualified server name string fullyQualifiedServerName = this.SqlConnectionContext.ServerName + DataServiceConstants.AzureSqlDatabaseDnsSuffix; // Issue the request ImportExportRequest context = this.ExportSqlAzureDatabaseProcess( this.SqlConnectionContext.ServerName, new Uri(blobUri), accessKey, fullyQualifiedServerName, this.DatabaseName, this.SqlConnectionContext.SqlCredentials); this.WriteObject(context); } catch (Exception ex) { this.WriteErrorDetails(ex); } }
/// <summary> /// Performs the call to import database using the server data service context channel. /// </summary> /// <param name="serverName">The name of the server to connect to.</param> /// <param name="blobUri">The storage blob Uri to import from.</param> /// <param name="storageAccessKey">The access key for the given storage blob.</param> /// <param name="fullyQualifiedServerName">The fully qualified server name.</param> /// <param name="databaseName">The name of the database for import.</param> /// <param name="edition">The edition of the database for import.</param> /// <param name="maxDatabaseSizeInGB">The database size for import.</param> /// <param name="sqlCredentials">The credentials used to connect to the database.</param> /// <returns>The result of the import request. Upon success the <see cref="ImportExportRequest"/> /// for the request</returns> internal ImportExportRequest ImportSqlAzureDatabaseProcess( string serverName, Uri blobUri, string storageAccessKey, string fullyQualifiedServerName, string databaseName, string edition, int maxDatabaseSizeInGB, SqlAuthenticationCredentials sqlCredentials) { this.WriteVerbose("BlobUri: " + blobUri); this.WriteVerbose("ServerName: " + fullyQualifiedServerName); this.WriteVerbose("DatabaseName: " + databaseName); this.WriteVerbose("Edition: " + edition); this.WriteVerbose("MaxDatabaseSizeInGB: " + maxDatabaseSizeInGB); this.WriteVerbose("UserName: " + sqlCredentials.UserName); // Get the SQL management client for the current subscription SqlManagementClient sqlManagementClient = GetCurrentSqlClient(); // Start the database export operation DacImportExportResponse response = sqlManagementClient.Dac.Import( serverName, new DacImportParameters() { BlobCredentials = new DacImportParameters.BlobCredentialsParameter() { Uri = blobUri, StorageAccessKey = storageAccessKey, }, ConnectionInfo = new DacImportParameters.ConnectionInfoParameter() { ServerName = fullyQualifiedServerName, DatabaseName = databaseName, UserName = sqlCredentials.UserName, Password = sqlCredentials.Password, }, AzureEdition = edition, DatabaseSizeInGB = maxDatabaseSizeInGB }); ImportExportRequest result = new ImportExportRequest() { OperationStatus = Services.Constants.OperationSuccess, OperationDescription = CommandRuntime.ToString(), OperationId = response.RequestId, RequestGuid = response.Guid, ServerName = serverName, SqlCredentials = sqlCredentials, }; return(result); }
/// <summary> /// Process the import request /// </summary> protected override void ProcessRecord() { try { base.ProcessRecord(); string accessKey = null; string blobUri = null; switch (this.ParameterSetName) { case ByContainerNameParameterSet: accessKey = System.Convert.ToBase64String( this.StorageContext.StorageAccount.Credentials.ExportKey()); blobUri = this.StorageContext.BlobEndPoint + this.StorageContainerName + "/" + this.BlobName; break; case ByContainerObjectParameterSet: accessKey = System.Convert.ToBase64String( this.StorageContainer.CloudBlobContainer.ServiceClient.Credentials.ExportKey()); blobUri = this.StorageContainer.Context.BlobEndPoint + this.StorageContainer.Name + "/" + this.BlobName; break; } string fullyQualifiedServerName = this.SqlConnectionContext.ServerName + DataServiceConstants.AzureSqlDatabaseDnsSuffix; // Create Web Request Inputs - Blob Storage Credentials and Server Connection Info ImportInput importInput = new ImportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = accessKey, Uri = blobUri }, ConnectionInfo = new ConnectionInfo { ServerName = fullyQualifiedServerName, DatabaseName = this.DatabaseName, UserName = this.SqlConnectionContext.SqlCredentials.UserName, Password = this.SqlConnectionContext.SqlCredentials.Password } }; if (this.MyInvocation.BoundParameters.ContainsKey("Edition")) { importInput.AzureEdition = this.Edition.ToString(); } if (this.MyInvocation.BoundParameters.ContainsKey("DatabaseMaxSize")) { importInput.DatabaseSizeInGB = this.DatabaseMaxSize; } ImportExportRequest request = this.ImportSqlAzureDatabaseProcess(this.SqlConnectionContext.ServerName, importInput); if (request != null) { request.SqlCredentials = this.SqlConnectionContext.SqlCredentials; request.ServerName = this.SqlConnectionContext.ServerName; this.WriteObject(request); } } catch (Exception ex) { SqlDatabaseExceptionHandler.WriteErrorDetails( this, this.SqlConnectionContext.ClientRequestId, ex); } }
/// <summary> /// Process the export request /// </summary> protected override void ProcessRecord() { this.WriteVerbose("Starting to process the record"); try { base.ProcessRecord(); string accessKey = null; string blobUri = null; switch (this.ParameterSetName) { case ByContainerNameParameterSet: accessKey = System.Convert.ToBase64String( this.StorageContext.StorageAccount.Credentials.ExportKey()); blobUri = this.StorageContext.BlobEndPoint + this.StorageContainerName + "/" + this.BlobName; break; case ByContainerObjectParameterSet: accessKey = System.Convert.ToBase64String( this.StorageContainer.CloudBlobContainer.ServiceClient.Credentials.ExportKey()); blobUri = this.StorageContainer.Context.BlobEndPoint + this.StorageContainer.Name + "/" + this.BlobName; break; } string fullyQualifiedServerName = this.SqlConnectionContext.ServerName + DataServiceConstants.AzureSqlDatabaseDnsSuffix; // Create Web Request Inputs - Blob Storage Credentials and Server Connection Info ExportInput exportInput = new ExportInput { BlobCredentials = new BlobStorageAccessKeyCredentials { StorageAccessKey = accessKey, Uri = blobUri }, ConnectionInfo = new ConnectionInfo { ServerName = fullyQualifiedServerName, DatabaseName = this.DatabaseName, UserName = this.SqlConnectionContext.SqlCredentials.UserName, Password = this.SqlConnectionContext.SqlCredentials.Password } }; this.WriteVerbose("AccessKey: " + accessKey); this.WriteVerbose("blobUri: " + blobUri); this.WriteVerbose("ServerName: " + exportInput.ConnectionInfo.ServerName); this.WriteVerbose("DatabaseName: " + exportInput.ConnectionInfo.DatabaseName); this.WriteVerbose("UserName: "******"Password: " + exportInput.ConnectionInfo.Password); ImportExportRequest request = this.ExportSqlAzureDatabaseProcess(this.SqlConnectionContext.ServerName, exportInput); if (request != null) { request.SqlCredentials = this.SqlConnectionContext.SqlCredentials; request.ServerName = this.SqlConnectionContext.ServerName; this.WriteObject(request); } } catch (Exception ex) { SqlDatabaseExceptionHandler.WriteErrorDetails( this, this.SqlConnectionContext.ClientRequestId, ex); } }