Exemplo n.º 1
0
        private static void CreateDatabaseFromRestorePoint(IAzure azure)
        {
            ISqlServer   sqlServer = azure.SqlServers.GetById(sqlSubscriptionId);
            ISqlDatabase database  = sqlServer.Databases.Get(sourceDatabase);

            // Let the user know something is happening
            Console.WriteLine("Starting creation of new database from restore point of existing item");
            Console.WriteLine("This can take a long time...");

            // There only ever seems to be one come back...?
            IRestorePoint restorePoint = database.ListRestorePoints()[0];

            // Select the Elastic Pool to deploy too
            ISqlElasticPool elasticPool = sqlServer.ElasticPools.Get(sqlElasticPoolName);

            // Restore the database from 5 minutes ago to a random name prefixed with Example_
            string dbName = SdkContext.RandomResourceName("Example_", 20);

            ISqlDatabase newDatabase = sqlServer.Databases
                                       .Define(dbName)
                                       .WithExistingElasticPool(elasticPool)
                                       .FromRestorePoint(restorePoint, DateTime.UtcNow.AddMinutes(-5))
                                       .Create();

            // The process is finished...
            Console.WriteLine($"Database {newDatabase.Name} deployed to pool {elasticPool.Name}");
        }
Exemplo n.º 2
0
        public void AddFilesToLatestPoint(List <FileInfo> ListOfNewFiles)
        {
            Debug.Assert(ListOfNewFiles != null, "ListOfNewFiles is null!");

            IRestorePoint lastPoint = GetLastPoint();

            lastPoint.AddNewListOfFiles(ListOfNewFiles);
        }
Exemplo n.º 3
0
        public bool IsRemovable(Backup backup, IRestorePoint restorePoint)
        {
            int pos = backup.RestorePoints.IndexOf(restorePoint);

            if (backup.RestorePoints.Count > 1 && backup.RestorePoints[pos + 1] is IncRestorePoint)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        ///GENMHASH:F6C12109AEE137840B60E059E6708A02:3802C120362CEFDF42D356C4A1BB4C0B
        public SqlDatabaseImpl FromRestorePoint(IRestorePoint restorePoint)
        {
            if (restorePoint == null)
            {
                throw new ArgumentNullException("restorePoint");
            }
            this.Inner.RestorePointInTime = restorePoint.EarliestRestoreDate;
            return(this.WithSourceDatabase(restorePoint.DatabaseId)
                   .WithMode(CreateMode.PointInTimeRestore));

            return(this);
        }
 public void Copy(Storage directory, IRestorePoint point)
 {
     if (point is IncrementRestorePoint incrementPoint)
     {
         var delta = incrementPoint.Delta;
         var files = incrementPoint.Files.Select(file =>
                                                 new File(file.Name, file.Length * (delta / 100))).ToList();
         foreach (var file in files)
         {
             directory.FilesList.Add(file);
         }
     }
     else
     {
         foreach (var file in point.Files)
         {
             directory.FilesList.Add(file);
         }
     }
 }
Exemplo n.º 6
0
        public void Copy(Storage directory, IRestorePoint point)
        {
            var memory = 0;

            if (point is IncrementRestorePoint incrementPoint)
            {
                var delta = incrementPoint.Delta;
                memory = incrementPoint.Files.Sum(file => file.Length * (delta / 100));
            }
            else
            {
                foreach (var file in point.Files)
                {
                    memory += file.Length;
                }
            }

            var name  = String.Format("Arch {0}", directory.FilesList.Count);
            var ifile = new File(name, memory);

            directory.FilesList.Add(ifile);
        }
Exemplo n.º 7
0
        public void ExecuteOperation()
        {
            if (migratorName == "")
                return;

            if (operationDescription != null && !executed &&
                operationDescription.OperationType != MigrationOperationTypes.DoNothing)
            {
                Migrator currentMigrator = GetMigratorByVersion(operationDescription.CurrentVersion);

                //if we are creating default, do it now
                if (operationDescription.OperationType == MigrationOperationTypes.CreateDefaultAndUpgradeToTarget)
                {
                    try
                    {
                        currentMigrator.CreateDefaults(genericData);
                    }
                    catch
                    {
                    }
                    executed = true;
                }

                //lets first validate where we think we are
                bool validated = currentMigrator != null && currentMigrator.Validate(genericData);

                if (!validated && validateTables && currentMigrator != null)
                {
                    //Try rerunning the migrator and then the validation
                    //prepare restore point if something goes wrong
                    MainConsole.Instance.Fatal(string.Format("[Migrator]: Failed to validate migration {0}-{1}, retrying...",
                                                             currentMigrator.MigrationName, currentMigrator.Version));

                    currentMigrator.Migrate(genericData);
                    validated = currentMigrator.Validate(genericData);
                    if (!validated)
                    {
                        SchemaDefinition rec;
                        currentMigrator.DebugTestThatAllTablesValidate(genericData, out rec);
                        MainConsole.Instance.Fatal(string.Format(
                            "[Migrator]: FAILED TO REVALIDATE MIGRATION {0}-{1}, FIXING TABLE FORCIBLY... NEW TABLE NAME {2}",
                            currentMigrator.MigrationName,
                            currentMigrator.Version,
                            rec.Name + "_broken"
                                                       ));
                        genericData.RenameTable(rec.Name, rec.Name + "_broken");
                        currentMigrator.Migrate(genericData);
                        validated = currentMigrator.Validate(genericData);
                        if (!validated)
                        {
                            throw new MigrationOperationException(string.Format(
                                "[Migrator]: Current version {0}-{1} did not validate. Stopping here so we don't cause any trouble. No changes were made.",
                                currentMigrator.MigrationName,
                                currentMigrator.Version
                                                                      ));
                        }
                    }
                }
                //else
                //    MainConsole.Instance.Fatal (string.Format ("Failed to validate migration {0}-{1}, continueing...", currentMigrator.MigrationName, currentMigrator.Version));

                bool restoreTaken = false;
                //Loop through versions from start to end, migrating then validating
                Migrator executingMigrator = GetMigratorByVersion(operationDescription.StartVersion);

                //only restore if we are going to do something
                if (executingMigrator != null)
                {
                    if (validateTables && currentMigrator != null)
                    {
                        //prepare restore point if something goes wrong
                        restorePoint = currentMigrator.PrepareRestorePoint(genericData);
                        restoreTaken = true;
                    }
                }

                while (executingMigrator != null)
                {
                    try
                    {
                        executingMigrator.Migrate(genericData);
                    }
                    catch (Exception ex)
                    {
                        if (currentMigrator != null)
                            throw new MigrationOperationException(string.Format("[Migrator]: Migrating to version {0} failed, {1}.",
                                                                                currentMigrator.Version, ex));
                    }
                    executed = true;
                    validated = executingMigrator.Validate(genericData);

                    //if it doesn't validate, rollback
                    if (!validated && validateTables)
                    {
                        RollBackOperation();
                        if (currentMigrator != null)
                            throw new MigrationOperationException(
                                string.Format("[Migrator]: Migrating to version {0} did not validate. Restoring to restore point.",
                                              currentMigrator.Version));
                    }
                    else
                    {
                        executingMigrator.FinishedMigration(genericData);
                    }

                    if (executingMigrator.Version == operationDescription.EndVersion)
                        break;

                    executingMigrator = GetMigratorAfterVersion(executingMigrator.Version);
                }

                if (restoreTaken)
                {
                    currentMigrator.ClearRestorePoint(genericData);
                }
            }
        }
        public void ExecuteOperation()
        {
            if (migratorName == "")
            {
                return;
            }

            if (operationDescription != null && !executed &&
                operationDescription.OperationType != MigrationOperationTypes.DoNothing)
            {
                Migrator currentMigrator = GetMigratorByVersion(operationDescription.CurrentVersion);

                //if we are creating default, do it now
                if (operationDescription.OperationType == MigrationOperationTypes.CreateDefaultAndUpgradeToTarget)
                {
                    try
                    {
                        currentMigrator.CreateDefaults(genericData);
                    }
                    catch
                    {
                    }
                    executed = true;
                }

                //lets first validate where we think we are
                bool validated = currentMigrator != null && currentMigrator.Validate(genericData);

                if (!validated && validateTables && currentMigrator != null)
                {
                    //Try rerunning the migrator and then the validation
                    //prepare restore point if something goes wrong
                    MainConsole.Instance.Fatal(string.Format("[Migrator]: Failed to validate migration {0}-{1}, retrying...",
                                                             currentMigrator.MigrationName, currentMigrator.Version));

                    currentMigrator.Migrate(genericData);
                    validated = currentMigrator.Validate(genericData);
                    if (!validated)
                    {
                        SchemaDefinition rec;
                        currentMigrator.DebugTestThatAllTablesValidate(genericData, out rec);
                        MainConsole.Instance.Fatal(string.Format(
                                                       "[Migrator]: FAILED TO REVALIDATE MIGRATION {0}-{1}, FIXING TABLE FORCIBLY... NEW TABLE NAME {2}",
                                                       currentMigrator.MigrationName,
                                                       currentMigrator.Version,
                                                       rec.Name + "_broken"
                                                       ));
                        genericData.RenameTable(rec.Name, rec.Name + "_broken");
                        currentMigrator.Migrate(genericData);
                        validated = currentMigrator.Validate(genericData);
                        if (!validated)
                        {
                            throw new MigrationOperationException(string.Format(
                                                                      "[Migrator]: Current version {0}-{1} did not validate. Stopping here so we don't cause any trouble. No changes were made.",
                                                                      currentMigrator.MigrationName,
                                                                      currentMigrator.Version
                                                                      ));
                        }
                    }
                }
                //else
                //    MainConsole.Instance.Fatal (string.Format ("Failed to validate migration {0}-{1}, continueing...", currentMigrator.MigrationName, currentMigrator.Version));


                bool restoreTaken = false;
                //Loop through versions from start to end, migrating then validating
                Migrator executingMigrator = GetMigratorByVersion(operationDescription.StartVersion);

                //only restore if we are going to do something
                if (executingMigrator != null)
                {
                    if (validateTables && currentMigrator != null)
                    {
                        //prepare restore point if something goes wrong
                        restorePoint = currentMigrator.PrepareRestorePoint(genericData);
                        restoreTaken = true;
                    }
                }


                while (executingMigrator != null)
                {
                    try
                    {
                        executingMigrator.Migrate(genericData);
                    }
                    catch (Exception ex)
                    {
                        if (currentMigrator != null)
                        {
                            throw new MigrationOperationException(string.Format("[Migrator]: Migrating to version {0} failed, {1}.",
                                                                                currentMigrator.Version, ex));
                        }
                    }
                    executed  = true;
                    validated = executingMigrator.Validate(genericData);

                    //if it doesn't validate, rollback
                    if (!validated && validateTables)
                    {
                        RollBackOperation();
                        if (currentMigrator != null)
                        {
                            throw new MigrationOperationException(
                                      string.Format("[Migrator]: Migrating to version {0} did not validate. Restoring to restore point.",
                                                    currentMigrator.Version));
                        }
                    }
                    else
                    {
                        executingMigrator.FinishedMigration(genericData);
                    }

                    if (executingMigrator.Version == operationDescription.EndVersion)
                    {
                        break;
                    }

                    executingMigrator = GetMigratorAfterVersion(executingMigrator.Version);
                }

                if (restoreTaken)
                {
                    currentMigrator.ClearRestorePoint(genericData);
                }
            }
        }
Exemplo n.º 9
0
        public void ExecuteOperation()
        {
            if (operationDescription != null && executed == false && operationDescription.OperationType != MigrationOperationTypes.DoNothing)
            {
                Migrator currentMigrator = GetMigratorByVersion(operationDescription.CurrentVersion);

                //if we are creating default, do it now
                if (operationDescription.OperationType == MigrationOperationTypes.CreateDefaultAndUpgradeToTarget)
                {
                    try
                    {
                        currentMigrator.CreateDefaults(genericData);
                    }
                    catch
                    {
                    }
                    executed = true;
                }

                if (validateTables)
                {
                    //lets first validate where we think we are
                    bool validated = currentMigrator.Validate(genericData);

                    if (!validated)
                    {
                        throw new MigrationOperationException(string.Format("Current version {0} did not validate. Stopping here so we don't cause any trouble. No changes were made.", currentMigrator.Version));
                    }
                }

                bool restoreTaken = false;
                //Loop through versions from start to end, migrating then validating
                Migrator executingMigrator = GetMigratorByVersion(operationDescription.StartVersion);

                //only restore if we are going to do something
                if (executingMigrator != null)
                {
                    if (validateTables)
                    {
                        //prepare restore point if something goes wrong
                        restorePoint = currentMigrator.PrepareRestorePoint(genericData);
                        restoreTaken = true;
                    }
                }


                while (executingMigrator != null)
                {
                    try
                    {
                        executingMigrator.Migrate(genericData);
                    }
                    catch (Exception)
                    {
                    }
                    executed = true;
                    if (validateTables)
                    {
                        bool validated = executingMigrator.Validate(genericData);

                        //if it doesn't validate, rollback
                        if (!validated)
                        {
                            RollBackOperation();
                            throw new MigrationOperationException(string.Format("Migrating to version {0} did not validate. Restoring to restore point.", currentMigrator.Version));
                        }
                    }

                    if (executingMigrator.Version == operationDescription.EndVersion)
                    {
                        break;
                    }

                    executingMigrator = GetMigratorAfterVersion(executingMigrator.Version);
                }

                if (restoreTaken)
                {
                    currentMigrator.ClearRestorePoint(genericData);
                }
            }
        }
Exemplo n.º 10
0
        public void ExecuteOperation()
        {
            if (operationDescription != null && executed == false && operationDescription.OperationType != MigrationOperationTypes.DoNothing)
            {
                Migrator currentMigrator = GetMigratorByVersion(operationDescription.CurrentVersion);

                //if we are creating default, do it now
                if (operationDescription.OperationType == MigrationOperationTypes.CreateDefaultAndUpgradeToTarget)
                {
                    try
                    {
                        currentMigrator.CreateDefaults(sessionProvider, genericData);
                    }
                    catch
                    {
                    }
                    executed = true;
                }

                //lets first validate where we think we are
                bool validated = currentMigrator.Validate(sessionProvider, genericData);

                if (!validated)
                {
                    throw new MigrationOperationException(string.Format("Current version {0} did not validate. Stopping here so we don't cause any trouble. No changes were made.", currentMigrator.Version));
                }

                bool restoreTaken = false;
                //Loop through versions from start to end, migrating then validating
                Migrator executingMigrator = GetMigratorByVersion(operationDescription.StartVersion);

                //only restore if we are going to do something
                if (executingMigrator != null)
                {
                    //prepare restore point if something goes wrong
                    restorePoint = currentMigrator.PrepareRestorePoint(sessionProvider, genericData);
                    restoreTaken = true;
                }


                while (executingMigrator != null)
                {
                    try
                    {
                        executingMigrator.Migrate(sessionProvider, genericData);
                    }
                    catch (Exception)
                    {
                        
                    }
                    executed = true;
                    validated = executingMigrator.Validate(sessionProvider, genericData);

                    //if it doesn't validate, rollback
                    if (!validated)
                    {
                        RollBackOperation();
                        throw new MigrationOperationException(string.Format("Migrating to version {0} did not validate. Restoring to restore point.", currentMigrator.Version));
                    }

                    if( executingMigrator.Version == operationDescription.EndVersion )
                    {
                        break;
                    }

                    executingMigrator = GetMigratorAfterVersion(executingMigrator.Version);
                }

                if (restoreTaken )
                {
                    currentMigrator.ClearRestorePoint(genericData);    
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Creates a new database from a restore point.
 /// </summary>
 /// <param name="restorePoint">The restore point.</param>
 /// <param name="restorePointDateTime">Date and time to restore from.</param>
 /// <return>The next stage of the definition.</return>
 SqlDatabase.Definition.IWithAttachAfterElasticPoolOptions <SqlElasticPoolOperations.Definition.IWithCreate> SqlDatabase.Definition.IWithRestorePointDatabaseAfterElasticPoolBeta <SqlElasticPoolOperations.Definition.IWithCreate> .FromRestorePoint(IRestorePoint restorePoint, DateTime restorePointDateTime)
 {
     return(this.FromRestorePoint(restorePoint, restorePointDateTime) as SqlDatabase.Definition.IWithAttachAfterElasticPoolOptions <SqlElasticPoolOperations.Definition.IWithCreate>);
 }
Exemplo n.º 12
0
 public void RemoveRestorePoint(IRestorePoint restorePoint)
 {
     RestorePoints.Remove(restorePoint);
 }
Exemplo n.º 13
0
 public void AddRestorePoint(IRestorePoint restorePoint)
 {
     RestorePoints.Add(restorePoint);
 }
Exemplo n.º 14
0
 ///GENMHASH:65DFD5CF3EED2BB07512CC188E7D8F8A:AFBA1099FDE55B08EE2A943E817A4A4B
 public SqlDatabaseForElasticPoolImpl FromRestorePoint(IRestorePoint restorePoint, DateTime restorePointDateTime)
 {
     this.sqlDatabase.FromRestorePoint(restorePoint, restorePointDateTime);
     return(this);
 }