Beispiel #1
0
        public static List <string> RestoreCleanupShrinkDB(DBRestoreParam dBRestoreParam, string DBName, bool ValidateParam = true)
        {
            List <string> RetList       = new List <string>(5);
            string        sqlBackupfile = string.Empty;
            string        outMessage    = string.Empty;

            if (ValidateParam)
            {
                if ((dBRestoreParam == null) || (!dBRestoreParam.IsValid(out outMessage)))
                {
                    RetList.Add(outMessage);
                    return(RetList);
                }
            }

            DbConnectionStringBuilder dbConnBuilder = new DbConnectionStringBuilder();

            dbConnBuilder.ConnectionString = dBRestoreParam.TargetServer.ConnString;

            RetList.Add(CopyBackupFromNetwork(dBRestoreParam, DBName, out sqlBackupfile));
            RetList.Add(RestoreBackup(sqlBackupfile, dBRestoreParam, DBName));
            RetList.Add(CleanupTables(DBName, dBRestoreParam));
            RetList.Add(ShrinkDatabase(DBName, dBRestoreParam));
            RetList.Add(FixDbUserLogin(DBName, dBRestoreParam));

            if (dBRestoreParam.PostRestore.DeleteLocalCopy)
            {
                RetList.Add(DeleteBackupFile(sqlBackupfile));
            }

            return(RetList);
        }
Beispiel #2
0
        public static List <string> RestoreCleanupShrinkDB(DBRestoreParam dBRestoreParam)
        {
            List <string> RetList    = new List <string>(5);
            string        outMessage = string.Empty;

            if ((dBRestoreParam == null) || (!dBRestoreParam.IsValid(out outMessage)))
            {
                RetList.Add(outMessage);
            }
            else
            {
                string[] databasesToRestore = dBRestoreParam.DatabasesToRestore.ToArray();
                string   sqlBackupfile      = string.Empty;
                foreach (string dbName in databasesToRestore)
                {
                    RetList.Add("Working on DB:" + dbName);
                    RetList.AddRange(RestoreCleanupShrinkDB(dBRestoreParam, dbName, false));
                    RetList.Add("Done with DB:" + dbName);
                }
            }

            return(RetList);
        }
Beispiel #3
0
        public static List <string> RestoreCleanupShrinkDB(string jsonFilePath)
        {
            List <string>  RetList    = new List <string>(5);
            DBRestoreParam dbparam    = DBRestoreParam.NewDBRestoreParam(jsonFilePath);
            string         outMessage = string.Empty;

            if ((dbparam != null) && (dbparam.IsValid(out outMessage)))
            {
                string sqlBackupfile = string.Empty;

                foreach (string dbName in dbparam.DatabasesToRestore)
                {
                    RetList.Add("Working on DB:" + dbName);
                    RetList.AddRange(RestoreCleanupShrinkDB(dbparam, dbName, false));
                    RetList.Add("Done with DB:" + dbName);
                }
            }
            else
            {
                RetList.Add(outMessage);
            }
            return(RetList);
        }