Beispiel #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);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Verify availability database states match expected values.
        /// </summary>
        public static void VerifyDatabaseStates(SMO.Server server, string agName, string dbName, bool expJoinedState, bool expSuspendedState, AvailabilityDatabaseSynchronizationState expSyncState)
        {
            bool currState;

            currState = AGDBHelper.GetDbJoinedState(agName, dbName, server);

            currState = AGDBHelper.GetDbSuspendedState(agName, dbName, server);

            AvailabilityDatabase db = AGDBHelper.GetDb(agName, dbName, server);

            db.Refresh();
            AvailabilityDatabaseSynchronizationState currSyncState = db.SynchronizationState;
        }
Beispiel #3
0
        /// <summary>
        /// Configure an Availability group. This performs the following steps
        /// <list type="number">
        /// <item>Join the secondary replica to the AG.</item>
        /// <item>Backup the databases from primary replica and restores it in secondary.</item>
        /// <item>Joins the database to primary.</item>
        /// </list>
        /// </summary>
        /// <param name="agName"></param>
        /// <param name="primaryReplica"></param>
        /// <param name="secondaryReplica"></param>
        /// <param name="databases"></param>
        /// <param name="fileShare"></param>
        public static void ConfigureAG(string agName, Smo.Server primaryReplica, Smo.Server secondaryReplica, IEnumerable <Database> databases, string fileShare)
        {
            ARHelper.JoinAG(agName, secondaryReplica);

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

            foreach (Database db in databases)
            {
                AGDBHelper.JoinAG(db.Name, agName, secondaryReplica);
            }
        }
Beispiel #4
0
        public void BackupLog()
        {
            while (!stopBackup)
            {
                dbCacheLock.EnterReadLock();
                try
                {
                    Console.WriteLine("Running log backup for {0} databases at background", primaryDbs.Count);
                    foreach (Database db in primaryDbs)
                    {
                        AGDBHelper.LogBackup(dbshare, primary, db.Name);
                    }
                }finally
                {
                    dbCacheLock.ExitReadLock();
                }

                Thread.Sleep(new TimeSpan(0, 2, 0));
            }
        }
Beispiel #5
0
        public void AddDatabasesIntoAG(List <string> listDbNames)
        {
            AvailabilityGroup ag = primary.AvailabilityGroups[agName];

            if (ag == null)
            {
                return;
            }
            foreach (string dbname in listDbNames)
            {
                AvailabilityDatabase adb = new AvailabilityDatabase(ag, dbname);
                adb.Create();
                foreach (Smo.Server srv in secondaries)
                {
                    AGDBHelper.JoinAG(dbname, agName, srv);
                    Thread.Sleep(1000);
                }

                // wait a bit to let adb join ag
            }
        }
Beispiel #6
0
 public static void BackUpAndRestoreDatabase(string fileShare, SMO.Server sourceServer, SMO.Server targetServer, string dbName)
 {
     AGDBHelper.BackupDatabase(fileShare, sourceServer, dbName);
     AGDBHelper.RestoreDatabase(fileShare, targetServer, dbName);
 }
Beispiel #7
0
 public static void SetDbSuspended(string agName, string dbName, SMO.Server server)
 {
     AGDBHelper.SetDbState(agName, dbName, true, server);
 }
Beispiel #8
0
 public static void SetDbOnline(string agName, string dbName, SMO.Server server)
 {
     AGDBHelper.SetDbState(agName, dbName, false, server);
 }