コード例 #1
0
        public void CreateDatabaseFromBackup(List <string> newDBNames)
        {
            foreach (string dbName in newDBNames)
            {
                primary.Databases.Refresh();
                if (!primary.Databases.Contains(dbName))
                {
                    AGDBHelper.RestoreDatabaseWithRename(baseDBpath, primary, "Test", dbName, false);
                    primary.Databases.Refresh();
                    if (primary.Databases.Contains(dbName))
                    {
                        Database db = primary.Databases[dbName];
                        primaryDbs.Add(db);

                        db.RecoveryModel = RecoveryModel.Full;
                        db.Alter();

                        AGDBHelper.BackupDatabase(dbshare, primary, dbName);
                        foreach (Smo.Server srv in secondaries)
                        {
                            AGDBHelper.RestoreDatabaseWithRename(dbshare, srv, dbName, dbName, false, true);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Configure an Availability group for multiple secondary replicas. This performs the following steps
        /// <list type="number">
        /// <item>Backup databases on primary.</item>
        /// <item>Join each secondary replica to the AG.</item>
        /// <item>Restore databases on each secondary replica.</item>
        /// <item>Join databases to AG on each secondary replica.</item>
        /// </list>
        /// </summary>
        /// <param name="agName"></param>
        /// <param name="primaryReplica"></param>
        /// <param name="secondaries"></param>
        /// <param name="databases"></param>
        /// <param name="fileShare"></param>
        public static void ConfigureAGforMS(string agName, Smo.Server primaryReplica, IEnumerable <Smo.Server> secondaries, IEnumerable <Database> databases, string fileShare)
        {
            foreach (Database db in databases)
            {
                AGDBHelper.BackupDatabase(fileShare, primaryReplica, db.Name);
            }

            foreach (Smo.Server secondaryReplica in secondaries)
            {
                ARHelper.JoinAG(agName, secondaryReplica);

                foreach (Database db in databases)
                {
                    AGDBHelper.RestoreDatabase(fileShare, secondaryReplica, db.Name);
                }

                foreach (Database db in databases)
                {
                    AGDBHelper.JoinAG(db.Name, agName, secondaryReplica);
                }
            }
        }
コード例 #3
0
ファイル: AGDBHelper.cs プロジェクト: zeroch/HadrBenchMark
 public static void BackUpAndRestoreDatabase(string fileShare, SMO.Server sourceServer, SMO.Server targetServer, string dbName)
 {
     AGDBHelper.BackupDatabase(fileShare, sourceServer, dbName);
     AGDBHelper.RestoreDatabase(fileShare, targetServer, dbName);
 }