/// <summary>
        /// Restore a given Sql Azure Database
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="restorePointInTime">A point to time to restore to (for PITR and dropped DB restore)</param>
        /// <param name="resourceId">The resource ID of the DB to restore (live, geo backup, deleted database, long term retention backup, etc.)</param>
        /// <param name="model">An object modeling the database to create via restore</param>
        /// <returns>Restored database object</returns>
        internal AzureSqlDatabaseModel RestoreDatabase(string resourceGroup, DateTime restorePointInTime, string resourceId, AzureSqlDatabaseModel model)
        {
            if (model.CreateMode.Equals("RestoreLongTermRetentionBackup", StringComparison.OrdinalIgnoreCase) && CultureInfo.CurrentCulture.CompareInfo.IndexOf(resourceId, "/providers/Microsoft.Sql", CompareOptions.IgnoreCase) >= 0)
            {
                // LongTermRetentionV2 Restore
                //
                Management.Sql.Models.Database database = Communicator.RestoreDatabase(resourceGroup, model.ServerName, model.DatabaseName, resourceId, model);

                return(new AzureSqlDatabaseModel(resourceGroup, model.ServerName, database));
            }
            else
            {
                DatabaseCreateOrUpdateParameters parameters = new DatabaseCreateOrUpdateParameters()
                {
                    Location   = model.Location,
                    Properties = new DatabaseCreateOrUpdateProperties()
                    {
                        Edition = model.Edition == DatabaseEdition.None ? null : model.Edition.ToString(),
                        RequestedServiceObjectiveId             = model.RequestedServiceObjectiveId,
                        ElasticPoolName                         = model.ElasticPoolName,
                        RequestedServiceObjectiveName           = model.RequestedServiceObjectiveName,
                        SourceDatabaseId                        = resourceId,
                        RecoveryServicesRecoveryPointResourceId = resourceId,
                        RestorePointInTime                      = restorePointInTime,
                        CreateMode = model.CreateMode
                    }
                };
                var resp = Communicator.LegacyRestoreDatabase(resourceGroup, model.ServerName, model.DatabaseName, parameters);
                return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroup, model.ServerName, resp));
            }
        }
Esempio n. 2
0
        private static string clientAppUri = "http://clientappuri";                  /* redirect URI */

        static void Main(string[] args)
        {
            var token = GetAccessToken();
            SqlManagementClient client = new SqlManagementClient(new TokenCloudCredentials(azureSubscriptionId, token.AccessToken));

            DatabaseCreateOrUpdateParameters databaseParameters = new DatabaseCreateOrUpdateParameters()
            {
                Location   = location,
                Properties = new DatabaseCreateOrUpdateProperties()
                {
                    Edition = edition,
                    RequestedServiceObjectiveName = requestedServiceObjectName,
                }
            };
            var dbResponse = client.Databases.CreateOrUpdate(resourceGroupName, serverName, databaseName, databaseParameters);

            Console.WriteLine("Database {0} created with status code: {1}. Service Objective: {2} ", dbResponse.Database.Name, dbResponse.StatusCode, dbResponse.Database.Properties.ServiceObjective);
        }
        /// <summary>
        /// Restore a given Sql Azure Database
        /// </summary>
        /// <param name="resourceGroup">The name of the resource group</param>
        /// <param name="restorePointInTime">A point to time to restore to (for PITR and dropped DB restore)</param>
        /// <param name="resourceId">The resource ID of the DB to restore (live, geo backup, or deleted database)</param>
        /// <param name="model">An object modeling the database to create via restore</param>
        /// <param name="parameters">Parameters describing the database restore request</param>
        /// <returns>Restored database object</returns>
        internal AzureSqlDatabaseModel RestoreDatabase(string resourceGroup, DateTime restorePointInTime, string resourceId, AzureSqlDatabaseModel model)
        {
            DatabaseCreateOrUpdateParameters parameters = new DatabaseCreateOrUpdateParameters()
            {
                Location   = model.Location,
                Properties = new DatabaseCreateOrUpdateProperties()
                {
                    Edition = model.Edition == DatabaseEdition.None ? null : model.Edition.ToString(),
                    RequestedServiceObjectiveId   = model.RequestedServiceObjectiveId,
                    ElasticPoolName               = model.ElasticPoolName,
                    RequestedServiceObjectiveName = model.RequestedServiceObjectiveName,
                    SourceDatabaseId              = resourceId,
                    RestorePointInTime            = restorePointInTime,
                    CreateMode = model.CreateMode
                }
            };
            var resp = Communicator.RestoreDatabase(resourceGroup, model.ServerName, model.DatabaseName, Util.GenerateTracingId(), parameters);

            return(AzureSqlDatabaseAdapter.CreateDatabaseModelFromResponse(resourceGroup, model.ServerName, resp));
        }
Esempio n. 4
0
        static DatabaseCreateOrUpdateResponse CreateOrUpdateDatabase(SqlManagementClient sqlMgmtClient, string resourceGroupName, string serverName, string databaseName, string databaseEdition, string databasePerfLevel)
        {
            // Retrieve the server that will host this database
            Server currentServer = sqlMgmtClient.Servers.Get(resourceGroupName, serverName).Server;

            // Create a database: configure create or update parameters and properties explicitly
            DatabaseCreateOrUpdateParameters newDatabaseParameters = new DatabaseCreateOrUpdateParameters()
            {
                Location   = currentServer.Location,
                Properties = new DatabaseCreateOrUpdateProperties()
                {
                    CreateMode = DatabaseCreateMode.Default,
                    Edition    = databaseEdition,
                    RequestedServiceObjectiveName = databasePerfLevel
                }
            };
            DatabaseCreateOrUpdateResponse dbResponse = sqlMgmtClient.Databases.CreateOrUpdate(resourceGroupName, serverName, databaseName, newDatabaseParameters);

            return(dbResponse);
        }
Esempio n. 5
0
 /// <summary>
 /// Restore a given Sql Azure Database
 /// </summary>
 /// <param name="resourceGroup">The name of the resource group</param>
 /// <param name="serverName">The name of the Azure SQL Server</param>
 /// <param name="databaseName">The name of the Azure SQL database</param>
 /// <param name="parameters">Parameters describing the database restore request</param>
 /// <returns>Restored database object</returns>
 public Management.Sql.Models.Database RestoreDatabase(string resourceGroupName, string serverName, string databaseName, string clientRequestId, DatabaseCreateOrUpdateParameters parameters)
 {
     return(GetCurrentSqlClient(clientRequestId).Databases.CreateOrUpdate(resourceGroupName, serverName, databaseName, parameters).Database);
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a copy of a Azure SQL Database with Legacy SDK model
 /// </summary>
 public Management.Sql.LegacySdk.Models.DatabaseCreateOrUpdateResponse CreateCopy(string resourceGroupName, string serverName, string databaseName, DatabaseCreateOrUpdateParameters parameters)
 {
     return(GetLegacySqlClient().Databases.CreateOrUpdate(resourceGroupName, serverName, databaseName, parameters));
 }
Esempio n. 7
0
 /// <summary>
 /// Creates a new Azure SQL Database or updates an existing Azure SQL
 /// Database.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the Microsoft.Azure.Management.Sql.IDatabaseOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the server
 /// belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server on which the
 /// database is hosted.
 /// </param>
 /// <param name='databaseName'>
 /// Required. The name of the Azure SQL Database to be operated on
 /// (Updated or created).
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for createing or updating a
 /// database.
 /// </param>
 /// <returns>
 /// Represents the response to a Get Database request.
 /// </returns>
 public static DatabaseGetResponse CreateOrUpdate(this IDatabaseOperations operations, string resourceGroupName, string serverName, string databaseName, DatabaseCreateOrUpdateParameters parameters)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IDatabaseOperations)s).CreateOrUpdateAsync(resourceGroupName, serverName, databaseName, parameters);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Esempio n. 8
0
 /// <summary>
 /// Creates a new Azure SQL Database or updates an existing Azure SQL
 /// Database.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the Microsoft.Azure.Management.Sql.IDatabaseOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the Resource Group to which the server
 /// belongs.
 /// </param>
 /// <param name='serverName'>
 /// Required. The name of the Azure SQL Database Server on which the
 /// database is hosted.
 /// </param>
 /// <param name='databaseName'>
 /// Required. The name of the Azure SQL Database to be operated on
 /// (Updated or created).
 /// </param>
 /// <param name='parameters'>
 /// Required. The required parameters for createing or updating a
 /// database.
 /// </param>
 /// <returns>
 /// Represents the response to a Get Database request.
 /// </returns>
 public static Task <DatabaseGetResponse> CreateOrUpdateAsync(this IDatabaseOperations operations, string resourceGroupName, string serverName, string databaseName, DatabaseCreateOrUpdateParameters parameters)
 {
     return(operations.CreateOrUpdateAsync(resourceGroupName, serverName, databaseName, parameters, CancellationToken.None));
 }