コード例 #1
0
        public void CopyUserObjects()
        {
            DateTime startTime = DateTime.Now;
            string   process   = "Copy Schema Objects";

            Memo("Start", string.Format("{0}: From {1}\r\n{0}:      [{2}]\r\n{0}:   To {3}\r\n{0}:      [{4}]\r\n",
                                        process, sourceObject.DatabaseSchema, sourceObject.Server, targetObject.DatabaseSchema, targetObject.Server));

            DropTables();

            if (!Abort)
            {
                CopyProcedures();
            }

            if (!Abort)
            {
                CopyFunctions();
            }

            if (!Abort)
            {
                CopyTables();
            }

            Memo("End", string.Format("\r\nCopy Schema Objects: {0, 7} {1}\r\n",
                                      "Elapsed", Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime)));
        }
コード例 #2
0
        void BackupSchema(string schema)
        {
            string process = "Backup Schema Objects";

            try
            {
                DateTime startTime = DateTime.Now;
                ActiveSchema = schema;

                Memo("Start", string.Format("/*\r\n**\t{0}\r\n**\t{1}: From {2}\r\n**\t{1}:      [{3}]\r\n**\t{1}:\r\n**\t{1}:   To {4}\r\n**\t{1}:      [{5}]\r\n*/\r\n",
                                            BackupTimeStamp, process,
                                            sourceObject.DatabaseSchema, sourceObject.Server,
                                            zipFile.Filename, zipFile.Path));

                zipFile.DeflateSchema(schema);

                BackupStoredObjects("Functions", schema);

                if (!abort)
                {
                    BackupStoredObjects("Procedures", schema);
                }

                if (!abort)
                {
                    BackupTables(schema);
                }

                zipFile.FinalizeSchema();

                foreach (Totals sTotals in zipFile.SchemaTypeTotals)
                {
                    Memo("Totals", string.Format("{0}: {1, 10:n0} Bytes ({2,10:n0} Compressed) - {3,7:n0} {4}",
                                                 process, sTotals.size, sTotals.deflated, sTotals.count, sTotals.Name));
                }

                Totals totals = zipFile.SchemaTotal;

                Memo("Totals", string.Format("{0}: {1, 10:n0} Bytes ({2,10:n0} Compressed) - {3,7:n0} ** Total Schema {4} Objects\r\n" +
                                             "{0}: {5, 28:n1}% {6, 23} {7}\r\n",
                                             process,
                                             totals.size, totals.deflated, totals.count, schema,
                                             totals.size > 0 ? 100.0 * totals.deflated / totals.size : 0.0,
                                             "**", abort ? "ABORTED" : VETimeStamp.ElapsedTime(startTime)));
            }
            catch (Exception e)
            {
                Error(string.Format("VEDataAdmin.BackupSchema: {0}", schema), e);
            }
        }
コード例 #3
0
        void BackupDatabase(string database)
        {
            if (database.ToLower().IndexOf("northwind") < 0)
            {
                try
                {
                    sourceCmd.ChangeDatabase(backupDatabase = database);

                    DateTime startTime = DateTime.Now;
                    string[] schemas   = sourceCmd.RetrieveUsers();

                    Memo("Start", string.Format("/**\r\n***\t{0}\r\n***\tBackup Database {1} - {2:n0} Schemas\r\n**/\r\n",
                                                BackupTimeStamp, backupServerDatabase, schemas.Length));

                    ZipFile.DeflateDatabase(database);
                    zipFile.InitializeSchemaNames(schemas);

                    for (int i = 0; i < schemas.Length && !abort; i++)
                    {
                        BackupSchema(schemas[i]);
                    }

                    zipFile.FinalizeDatabase();

                    foreach (Totals tTotals in zipFile.SchemaTotals)
                    {
                        Memo("Totals", string.Format("Backup Database Objects: {0, 13:n0} Bytes ({1,10:n0} Compressed) - {2,7:n0} Schema {3}",
                                                     tTotals.size, tTotals.deflated, tTotals.count, tTotals.Name));
                    }

                    Totals totals = zipFile.DatabaseTotal;

                    Memo("Totals", string.Format("Backup Database Objects: {0, 13:n0} Bytes ({1,10:n0} Compressed) - {2,7:n0} *** Total Database {3} Objects\r\n" +
                                                 "Backup Database Objects: {4, 31:n1}% {5, 24} {6}\r\n",
                                                 totals.size, totals.deflated, totals.count, database,
                                                 totals.size > 0 ? 100.0 * totals.deflated / totals.size : 0.0,
                                                 "***", abort ? "ABORTED" : VETimeStamp.ElapsedTime(startTime)));
                }
                catch (Exception e)
                {
                    Error("VEAdmin.BackupDatabase(database): " + database, e);
                }
                finally
                {
                    sourceCmd.ChangeDatabase(backupDatabase = SourceDatabase);
                }
            }
        }
コード例 #4
0
        void BackupDatabaseTables(string database)
        {
            DateTime startTime = DateTime.Now;

            sourceCmd.ChangeDatabase(backupDatabase = database);

            string[] schemas = sourceCmd.RetrieveUsers();

            Memo("Tables", string.Format("/*\r\n**\t{0}\r\n**\tBackup Database {1} - All Tables for {2:n0} Schemas\r\n*/\r\n",
                                         BackupTimeStamp, backupServerDatabase, schemas.Length));
            try
            {
                zipFile.InitializeSchemaNames(schemas);

                foreach (string schema in schemas)
                {
                    BackupTables(schema);

                    if (abort)
                    {
                        break;
                    }
                }

                Memo("Tables", string.Format("/*\r\n**\tBackup Database {0} - All Schema Tables: {1,7} {2}\r\n*/\r\n",
                                             backupServerDatabase, "***", abort ? "ABORTED" : VETimeStamp.ElapsedTime(startTime)));
            }
            catch (Exception e)
            {
                Memo("Exception", string.Format("\r\nBackup Database {0} - All Schema Tables: {1,7} {2}\r\n", backupServerDatabase, "ERROR", e.Message));
            }
            finally
            {
                sourceCmd.ChangeDatabase(backupDatabase = SourceDatabase);
            }
        }
コード例 #5
0
        public void BackupServer()
        {
            DateTime startTime = DateTime.Now;

            string[] databases = sourceCmd.ApplicationDatabases;

            Memo("Memo", string.Format("/***\r\n****\t{0}\r\n****\tBackup Server {1} - {2:n0} Databases\r\n***/\r\n",
                                       BackupTimeStamp, sourceObject.ServerID,                  // SourceServerAlias,
                                       databases.Length));

            try
            {
                ZipFile.InitializeServer(databases);
                errors.Clear();

                for (int i = 0; i < databases.Length && !abort; i++)
                {
                    BackupDatabase(SourceDatabase = databases[i]);
                }

                zipFile.FinalizeServer();

                foreach (Totals tTotals in zipFile.DatabaseTotals)
                {
                    Memo("Memo", string.Format("Backup Server Objects: {0, 13:n0} Bytes ({1,10:n0} Compressed) - {2,7:n0} Database {3}",
                                               tTotals.size, tTotals.deflated, tTotals.count, tTotals.Name));
                }

                Totals totals = zipFile.ServerTotal;

                Memo("Memo", string.Format("{0,21}  {1, 13:n0} Bytes ({2,10:n0} Compressed) - {3,7:n0} **** Total Server [{4}] Objects\r\n{5, 54:n2}%\r\n",
                                           "****", totals.size, totals.deflated, totals.count, sourceObject.ServerID,
                                           100.0f * totals.deflated / totals.size));
            }
            catch (Exception e)
            {
                Error(new string[] { "Backup Server Error: " + SourceServerDatabase, e.Message });
            }
            finally
            {
                SourceDatabase = null;
                zipFile.Close();
                Memo("Totals", string.Format("/***\r\n****\t{0}\r\n****\tBackup Server [{1}] Databases\r\n****\t{2}\r\n***\r\n",
                                             BackupTimeStamp, sourceObject.ServerID,
                                             abort ? "*** ABORTED ***" : "Completed: " + VETimeStamp.ElapsedTime(startTime)));
                ListErrors();
                Memo("End", "");
            }
        }
コード例 #6
0
        void BackupDatabaseStart(bool isEnd)
        {
            DateTime startTime = DateTime.Now;

            bool isNorthWind = SourceDatabase.ToLower().IndexOf("northwind") >= 0;

            textBackupDatabase = "BackupDatabase 1";

            try
            {
                if (!isNorthWind)                                               //	Can't handle Northwind images
                {
                    ZipFile.InitializeDatabase(SourceDatabase);
                    errors.Clear();
                    BackupDatabase(SourceDatabase);
                }
            }
            catch (Exception e)
            {
                Error("VEAdmin.BackupDatabase Error: " + textBackupDatabase + "\r\n" + e.Message);
            }
            finally
            {
                if (!isNorthWind)
                {
                    zipFile.Close();
                }

                Memo("Totals", string.Format("/***\r\n****\t{0}\r\n****\tBackup Database {1}\r\n****\t{2}\r\n***/\r\n",
                                             BackupTimeStamp, backupServerDatabase,
                                             abort ? "*** ABORTED ***" : isNorthWind ? "*** NorthWind Exclusion ***" : "Completed: " + VETimeStamp.ElapsedTime(startTime)));

                ListErrors();

                if (isEnd)
                {
                    Memo("End", "");
                }
            }
        }
コード例 #7
0
        void CopyObjects(bool isProcedure, string[] objectNames)
        {
            DateTime startTime = DateTime.Now;

            string text         = isProcedure ? "Procedure" : "Function",
                   objectName   = "",
                   proccessType = "Copy Schema " + text;

            Memo("Start", string.Format("{0}s: From {1}\r\n{0}s:      [{2}]\r\n{0}s:\r\n{0}s:   To {3}\r\n{0}s:      [{4}]\r\n",
                                        proccessType, sourceObject.DatabaseSchema, sourceObject.Server, targetObject.DatabaseSchema, targetObject.Server));

            try
            {
                objectCount = objectSize = 0;
                Abort       = false;

                for (int i = 0; i < objectNames.Length && !Abort; i++)
                {
                    sourceObject.ObjectName = objectName = objectNames[i];

                    if (objectName.IndexOf(SourceSchema + ".") != 0)
                    {
                        Memo("Error", string.Format("{0}s: {1, 7} NOT COPIED - {2}", proccessType, "SKIPPED", sourceObject.ServerIDObjectName));
                    }

                    else
                    {
                        int length = isProcedure ? CopyProcedureObject() : CopyFunctionObject();

                        if (length > 0)
                        {
                            objectSize += length;
                            objectCount++;
                        }
                        else
                        {
                            Error(string.Format("{0}s: {1, 7} NOT RETRIEVED - {2}", proccessType, "ERROR", sourceObject.ServerIDObjectName));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Error("VEDataAdmin.CopyObjects: " + text + " - " + objectName, e);
            }
            finally
            {
                text = string.Format("\r\n{0}s: {2, 7:n0} {3}{1}s Copied ({4:n0} Bytes) Of {5} \r\n{0}s: {6, -5} {7}\r\n",
                                     proccessType,
                                     text,
                                     objectCount,
                                     objectCount == objectNames.Length ? "" : "## ",
                                     objectSize,
                                     objectNames.Length,
                                     "**", Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime));

                if (!Abort)
                {
                    Memo("Totals", text);
                }
                else
                {
                    Error(text);
                }

                Status("");
            }
        }
コード例 #8
0
        public override void RestoreTables(VEDelegate taskCompletion)
        {
            DateTime startTime = DateTime.Now;
            int      count = 0, schemaCount = 0;
            bool     failed = false;

            Memo("Memo", string.Format("//\r\n//\t{0}\r\n//\tRestore User Tables: From {1}...\r\n" +
                                       "//\tRestore User Tables:   To {2}...\r\n//\r\n",
                                       BackupTimeStamp, restoreObject.Tables, targetObject.ServerIDDatabaseSchema));          //.ServerIDDatabaseUser));

            try
            {
                schemaCount = RestoreTableSchema();

                if (!(failed = schemaCount <= 0))
                {
                    count = RestoreTableObjects();
                }
            }
            catch (Exception e)
            {
                Memo("Memo", "VEAdmin.RestoreTables.Exception:\r\n\t" + e.Message);
                failed = true;
            }
            finally
            {
                Memo("Memo", string.Format("\r\n//\r\n//\tRestore User Tables: {0, 7:n0} Of {1:n0} Tables Restored" +
                                           "\r\n//\tRestore User Tables: {2, 7} {3}\r\n//\r\n",
                                           count, schemaCount, "**",
                                           Abort ? "Restoration Aborted" : failed ? "Restoration Failed" : VETimeStamp.ElapsedTime(startTime)));

                taskCompletion();
            }
        }
コード例 #9
0
        void BackupServerObjects(string type)
        {
            DateTime startTime = DateTime.Now;

            string[] databases = sourceCmd.ApplicationDatabases;

            Memo("Start", string.Format("/***\r\n****\t{0}\r\n****\tBackup Server [{1}] {2} - {3:n0} Databases\r\n***/\r\n",
                                        BackupTimeStamp, sourceObject.ServerID, type, databases.Length));

            try
            {
                ZipFile.InitializeServer(databases, type);

                foreach (string database in databases)
                {
                    if (!abort && database.ToLower().IndexOf("northwind") < 0)                                                  //	Can't handle Northwind images
                    {
                        ZipFile.DeflateDatabase(database);
                        BackupDatabaseObjects(SourceDatabase = database, type);
                    }
                }

                zipFile.FinalizeServer();

                foreach (Totals tTotals in zipFile.DatabaseTotals)
                {
                    Memo("Totals", string.Format("Backup Server {0}: {1, 13:n0} Bytes ({2,10:n0} Compressed) - {3,7:n0} Schema {4}",
                                                 type, tTotals.size, tTotals.deflated, tTotals.count, tTotals.Name));
                }

                Totals totals = zipFile.ServerTotal;
                string fmt    = string.Format("{{0,{0}}} ", 14 + type.Length);

                Memo("Totals", string.Format("{0} {1, 13:n0} Bytes ({2,10:n0} Compressed) - {3,7:n0} Server [{4}] {5}\r\n",
                                             string.Format(fmt, "****"),
                                             totals.size, totals.deflated, totals.count, sourceObject.ServerID, type));
            }
            catch (Exception e)
            {
                Error(string.Format("VEDataAdmin.BackupServerObjects: [{0}] {1}", sourceObject.ServerID, type), e);
            }
            finally
            {
                SourceDatabase = null;
                zipFile.Close();

                string text = string.Format("/***\r\n****\t{0}\r\n****\tBackup Server [{1}] {2}\r\n****\t{3}\r\n***/\r\n",
                                            BackupTimeStamp, sourceObject.ServerID, type,
                                            abort ? "*** ABORTED ***" : "Completed: " + VETimeStamp.ElapsedTime(startTime));

                if (!abort)
                {
                    Memo("End", text);
                }
                else
                {
                    Error(text);
                }
            }
        }
コード例 #10
0
        public void CopyTables()
        {
            DataTable dependencies = null;
            DateTime  startTime    = DateTime.Now;

            string process = "Copy Schema Tables";
            int    count   = 0;

            try
            {
                Memo("Start", string.Format("{0}: From {1}\r\n{0}:      [{2}]\r\n{0}:\r\n{0}:   To {3}\r\n{0}:      [{4}]\r\n",
                                            process, sourceObject.DatabaseSchema, sourceObject.Server, targetObject.DatabaseSchema, targetObject.Server));

                Status("Retrieving table dependencies for " + sourceObject.DatabaseSchema);

                if ((dependencies = GetTableDependencies(sourceCmd, SourceSchema)) != null)
                {
                    count = CopyTables(dependencies);
                }

                else
                {
                    Memo("Error", string.Format("\r\n{0}: {1, -7} Failed to retrieve table dependencies.  Errors -\r\n{0}: {1}", process, "ERROR", SQLHandler.Errors));
                }
            }
            //catch(Exception e)
            //{
            //	  //
            //	  // Use this only for trouble shooting - Exceptions need to be trapped by SQLErrorHandler
            //	  //
            //    VELog.Exception("CopyTables", e);
            //}
            finally
            {
                if (dependencies != null)
                {
                    Memo(Abort ? "Error" : "Totals", string.Format("\r\n{0}: {1, 7:n0}{2}Tables Copied Of {3}\r\n{0}: {4, -5} {5}\r\n",
                                                                   process, count,
                                                                   count == dependencies.Rows.Count ? " " : " ## ",
                                                                   dependencies.Rows.Count,
                                                                   "**",
                                                                   Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime)));
                }
            }
        }
コード例 #11
0
        public override void RestoreTables(VEDelegate taskCompletion)
        {
            DateTime startTime = DateTime.Now;
            int      count = 0, schemaCount = 0;
            bool     failed  = false;
            string   process = "Restore User Tables";

            Memo("Start", string.Format("//\r\n//\t{0}\r\n//\t{1}: From {2}\r\n//\t{1}:      [{3}]\r\n//\r\n//\t{1}:   To {4}\r\n//\t{1}:      [{5}]\r\n//\r\n",
                                        BackupTimeStamp, process,
                                        ZipFile.DatabaseSchema, ZipFile.FullFilename,
                                        targetObject.DatabaseSchema, targetObject.Server));

            try
            {
                if (zipFile.HasSchemaTables())
                {
                    zipFile.Objects("Tables");
                    schemaCount = RestoreTableSchema();

                    if (!(failed = schemaCount <= 0))
                    {
                        count = RestoreTableObjects();
                    }
                }
                else
                {
                    VELog.Error("VEAdminZip.RestoreTables: database = " + zipFile.Database + "; schema = " + zipFile.Schema + "; HasNoTables");
                }
            }
            catch (Exception e)
            {
                Error("VEAdminZip.RestoreTables Exception: ", e);
                failed = true;
            }
            finally
            {
                Memo(Abort || failed ? "Error" : "Totals", string.Format("\r\n//\r\n//\t{0}: {1, 7:n0} Of {2:n0} Tables Restored\r\n//\t{0}: {3, 7} {4}\r\n//\r\n",
                                                                         process, count, schemaCount, "**",
                                                                         Abort ? "Restoration Aborted" : failed ? "Restoration Failed" : VETimeStamp.ElapsedTime(startTime)));

                taskCompletion();

                VELog.Error(string.Format("VEAdminZip.RestoreTables: min = {0}; max = {1}; max1024 = {2}; max2048 = {3} ", minCommand, maxCommand, maxCommand1024, maxCommand2048));
            }
        }
コード例 #12
0
        protected void RestoreStoredObjects(string type, string[] names, VEBooleanDelegateString[] dropAndExists)
        {
            DateTime          startTime = DateTime.Now;
            int               count = 0, size = 0;
            DataRowCollection rows = null;

            string sourceSchema = zipFile.Schema,
                   targetSchema = targetObject.Schema,
                   processType  = "Restore Schema " + type;

            Memo("Start", string.Format("//\r\n//\t{0}\r\n//\t{1}: From {2}\r\n//\t{1}:      [{3}]\r\n//\r\n//\t{1}:   To {4}\r\n//\t{1}:      [{5}]\r\n//\r\n",
                                        BackupTimeStamp, processType,
                                        ZipFile.DatabaseSchema, ZipFile.FullFilename,
                                        targetObject.DatabaseSchema, targetObject.Server));

            try
            {
                RestoreDropObjects(type, names, dropAndExists[0]);

                rows = zipFile.Objects(type).Rows;

                foreach (DataRow row in rows)
                {
                    string name = (string)row["Name"];

                    Status("Restoring " + type + ": " + name);

                    string ownerObject = targetSchema + "." + name,
                           text        = zipFile.InflateText(type, name);

                    RestoreCreateObject(type, text, sourceSchema, targetSchema, ownerObject, dropAndExists[1], ref size, ref count);
                }
            }
            finally
            {
                Memo("Totals", string.Format("\r\n{0}: {1, 7:n0} Bytes - {2:n0} of {3:n0} {0} Created\r\n{0}: {4, 7} {5}\r\n",
                                             processType, size, count, rows.Count, "**", Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime)));
            }
        }
コード例 #13
0
        protected override Totals BackupTables(string schema)
        {
            DateTime startTime = DateTime.Now;

            ActiveSchema = schema;
            string process = "Backup Schema Tables";

            Memo("Start", string.Format("//\r\n//\t{0}\r\n//\t{1}: From {2}\r\n//\t{1}:      [{3}]\r\n//\t{1}:\r\n//\t{1}:   To {4}/r/n//\t{1}:      [{5}]\r\n//\r\n",
                                        BackupTimeStamp, process,
                                        sourceObject.DatabaseSchema, sourceObject.Server, backupObject.Paths["Tables"], backupObject.Server));

            try
            {
                string[] tablenames = sourceCmd.RetrieveTableNames(schema);

                if (tablenames.Length == 0)
                {
                    Memo("NONE", string.Format("Backup Schema Tables: {0, 7} There are no Tables to backup", "NONE"));
                }

                else if (!(Abort = !BackupTableDependencies()))
                {
                    int tableCount = 0, recordCount = 0, count = 0;

                    for (int i = 0; i < tablenames.Length && !Abort; i++)
                    {
                        backupObject.FileName = tablenames[i];

                        if (backupObject.ObjectName.ToLower() == veTableDependencies.ToLower() ||
                            backupObject.ObjectName.ToLower() == veTableSchema.ToLower() ||
                            backupObject.ObjectName.ToLower() == veTableDefinition.ToLower())
                        {
                            Memo("Memo", string.Format("Backup Schema Tables: {0, 7} Table INTENTIONALLY NOT BACKED UP - ...Data\\{1}", "-", backupObject.SchemaTable));
                        }

                        else
                        {
                            count = BackupTableObject(ref recordCount);

                            Memo("Memo", string.Format("Backup Schema Tables: {0, 7:n0}{1} Records written to ...Data\\{2}",
                                                       count, count != recordCount ? " ## Of " + recordCount.ToString("N0") : "", backupObject.TableFileName));

                            tableCount++;
                            BackupTableScript(GetSchemaDefinition(sourceCmd, backupObject.SchemaTable));
                        }
                    }

                    Memo("Totals", string.Format("\r\nBackup Schema Tables: {0, 7:n0} Tables {1} Copied",
                                                 tableCount, tableCount == tablenames.Length ? "" : "of " + tablenames.Length.ToString() + " Tables"));
                }
            }
            catch (Exception e)
            {
                Error("VEAdminFiles.BackupTables: " + schema, e);
            }
            finally
            {
                string text = string.Format("Backup Schema Tables: {0, 7} {1}\r\n", "**", Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime));

                if (!Abort)
                {
                    Memo("Totals", text);
                }
                else
                {
                    Error(text);
                }

                ActiveSchema = null;
                Status("");
            }

            return(null);
        }
コード例 #14
0
        protected void RestoreStoredObjects(string type, string path, string[] names, VEBooleanDelegateString[] dropAndExists)
        {
            DateTime     startTime = DateTime.Now;
            StreamReader file      = null;

            string [] files = Directory.GetFiles(path, "*.sql");

            int count = 0, size = 0;

            Memo("Memo", string.Format("//\r\n//\t{0}\r\n//\tRestore User {1}: From [Disk].{2}...\r\n" +
                                       "//\tRestore User {1}:   To {3}...\r\n//\r\n",
                                       BackupTimeStamp, type, path, targetObject.ServerIDDatabaseSchema));

            try
            {
                RestoreDropObjects(type, names, dropAndExists[0]);

                for (int i = 0; i < files.Length && !Abort; i++)
                {
                    string filename = files[i];
                    restoreObject.ObjectName = filename.Substring(0, filename.LastIndexOf('.'));

                    string ownerObject = restoreObject.SchemaObject;

                    file = File.OpenText(filename);

                    string text = file.ReadToEnd();

                    file.Close();
                    file = null;

                    RestoreCreateObject(type, text, restoreObject.FileSchema, restoreObject.Schema, restoreObject.SchemaObject, dropAndExists[1], ref size, ref count);

                    //int length = text.Length;

                    //if (text.Substring(0, length > 100 ? 100 : length).ToLower().IndexOf("create ") >= 0)
                    //{
                    //    if (restoreObject.FileSchema.Length > 0)
                    //        text = text.Replace(restoreObject.FileSchema, restoreObject.Schema).Replace(restoreObject.FileSchema.ToLower(), restoreObject.Schema);

                    //    targetCmd.Execute(text);

                    //    file.Close();
                    //    file = null;

                    //    if (dropAndExists[1](ownerObject))
                    //    {
                    //        Memo(string.Format("Restore User {0}: {1, 7:n0} Bytes - {2} Restored", type, length, ownerObject));
                    //        size += length;
                    //        count++;
                    //    }
                    //    else
                    //    {
                    //        count--;

                    //        Memo(string.Format("Restore User {0}: {1, 7} {2} NOT CREATED {3}",
                    //                type, "ERROR", ownerObject,
                    //                HasSQLErrors ? " - See below\r\n" + SQLErrors : ""));
                    //    }
                    //}
                }
            }
            finally
            {
                Memo("Memo", string.Format("\r\nRestore User {0}: {1, 7:n0} Bytes - {2:n0} of {3:n0} {0} Created" +
                                           "\r\nRestore User {0}: {4, 7} {5}\r\n",
                                           type, size, count, files.Length, "**", Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime)));

                if (file != null)
                {
                    file.Close();
                }
            }
        }
コード例 #15
0
        void BackupDatabaseObjects(string database, string type)
        {
            DateTime startTime = DateTime.Now;

            sourceCmd.ChangeDatabase(backupDatabase = database);

            string process = "Backup Database";

            string[] schemas = sourceCmd.RetrieveUsers();

            Memo("Start", string.Format("/*\r\n**\t{0}\r\n**\t{1} {2} {3} - {4:n0} Schema{5}\r\n*/\r\n",
                                        BackupTimeStamp, process, backupServerDatabase, type, schemas.Length, schemas.Length > 0 ? "s" : ""));

            try
            {
                zipFile.InitializeSchemaNames(schemas);

                foreach (string schema in schemas)
                {
                    zipFile.DeflateSchema(schema, type);

                    if (type == "Tables")
                    {
                        BackupTables(schema);
                    }
                    else
                    {
                        BackupStoredObjects(type, schema);
                    }

                    zipFile.FinalizeSchema();

                    if (abort)
                    {
                        break;
                    }
                }

                zipFile.FinalizeDatabase();

                foreach (Totals tTotals in zipFile.SchemaTotals)
                {
                    Memo("Totals", string.Format("{0} {1}: {2, 13:n0} Bytes ({3,10:n0} Compressed) - {4,7:n0} Schema {5}",
                                                 process, type, tTotals.size, tTotals.deflated, tTotals.count, tTotals.Name));
                }

                Totals totals = zipFile.DatabaseTotal;

                Memo(Abort ? "Error" : "Totals", string.Format("{0} {1}: {2, 13:n0} Bytes ({3,10:n0} Compressed) - {4,7:n0} *** Total Database {5} {6}\r\n" +
                                                               "Backup Database {0}: {6, 31:n1}% {7, 24} {8}\r\n",
                                                               process, type,
                                                               totals.size, totals.deflated, totals.count, database,
                                                               totals.size > 0 ? 100.0 * totals.deflated / totals.size : 0.0,
                                                               "***", abort ? "ABORTED" : VETimeStamp.ElapsedTime(startTime)));
            }
            catch (Exception e)
            {
                Error(string.Format("VEDataAdmin.BackupDatabaseObjects {0} - All Schema {1}", backupServerDatabase, type), e);
            }
        }
コード例 #16
0
        protected override Totals BackupStoredObjects(string type, string schema)
        {
            DateTime startTime   = DateTime.Now;
            Totals   totals      = null;
            string   processType = "Backup Schema " + type;
            int      count       = 0,
                     xcount      = 0;

            try
            {
                ActiveSchema = schema;

                Memo(type, string.Format("//\r\n//\t{0}\r\n//\t{1}: From {2}\r\n//\t{1}:      [{3}]\r\n//\t{1}:\r\n//\t{1}:   To {4}\r\n//\t{1}:      [{5}]\r\n//\r\n",
                                         BackupTimeStamp, processType,
                                         sourceObject.DatabaseSchema, sourceObject.Server, zipFile.Filename, zipFile.Path));

                Process("Backing up " + backupServerDatabase + ".");
                Status(string.Format("{0} to {1}", type, zipFile.FileDatabaseSchema));

                Abort = false;
                string[] objectNames = type == "Procedures" ? sourceCmd.RetrieveUserProcedures(schema)
                                                                                                                        : sourceCmd.RetrieveFunctionNames(schema);

                if (objectNames.Length > 0)
                {
                    foreach (string name in objectNames)
                    {
                        if (name.IndexOf(schema + ".") == 0)
                        {
                            zipFile.DeflateObjectName(schema, type, name);
                        }
                    }

                    if ((count = zipFile.DeflateObjectName(null)) > 0)
                    {
                        foreach (string name in objectNames)
                        {
                            if (name.IndexOf(schema + ".") == 0)
                            {
                                Status(name);
                                totals = zipFile.DeflateStoredObject(name, sourceCmd.RetrieveProcedureText(name));
                                xcount++;

                                Memo(type, string.Format("{0}: {1, 10:n0} Bytes ({2,10:n0} Compressed) {3}", processType, totals.size, totals.deflated, name));
                                Status("");

                                if (Abort)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }

                if (count == 0 || (totals = zipFile.TypeTotal).count == 0)
                {
                    Memo("NONE", string.Format("{0}: {1, -10} There are no Schema-qualified {0} to backup\r\n", processType, "NONE"));
                }

                else if (totals != null)
                {
                    Memo("Memo", string.Format("\r\n{0}: {1, 10:n0} Bytes ({2,10:n0} Compressed) - {3:n0} {0} Copied ", processType, totals.size, totals.deflated, totals.count));
                }
            }
            catch (Exception e)
            {
                Error("VEDataAdminZip.BackupStoredObjects: " + backupServerDatabase + "." + schema + "." + type, e);
                //errors.Add("VEAdmin.BackupStoredObjects Exception: " + backupServerDatabase + "." + schema + "." + type);
            }
            finally
            {
                if (xcount < count)
                {
                    Error(string.Format("{0}: {1, 10} Only {2:n0} of {3:n0} {0} Copied", processType, "", xcount, count));
                }

                else if (totals != null && totals.count > 0)
                {
                    Memo(Abort ? "Error" : "Memo", string.Format("{0}: {1, 28:n1}% {2, 12} {3}\r\n",
                                                                 processType, totals.size > 0 ? 100.0 * totals.deflated / totals.size : 0.0,
                                                                 "**", Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime)));
                }

                Process("");
                Status("");

                ActiveSchema = null;
            }

            return(totals);
        }
コード例 #17
0
        /// <summary>
        /// <para> 1. Retrieves a list of table names from VEDatabase.RetrieveTableNames </para>
        /// <para> 2. Prepares .ZipFile for deflating table names </para>
        /// <para> 3. Has .ZipFile reserve positions in the compressed file for each table </para>
        /// <para> 4. Compresses the script for creating table 'veTableDependencies' from .backupTableDependencies. </para>
        /// <para> 5. Compresses to file .backupTableDependencies column and values strings suitable for inserting all records into to the recreated file </para>
        /// <para> 6. For each of the tables </para>
        /// <para> 6.a. Compresses to file a script suitable for recreating the table </para>
        /// <para> 6.b. Compresses to file column and values strings suitable for inserting all records into the recreated table </para>
        /// <para> 7. Communicates compression results to the calling application for each table processed </para>
        /// <para> 8. Communicates the total compression results to the calling application for all schema tables </para>
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        protected override Totals BackupTables(string schema)
        {
            DateTime startTime = DateTime.Now;
            Totals   totals = null;
            int      tableCount = 0, recordCount = 0, totalRecords = 0, count = 0, xcount = 0;
            string   process = "Backup Schema Tables";

            ActiveSchema = schema;

            Memo("Memo", string.Format("//\r\n//\t{0}\r\n//\t{1}: From {2}\r\n//\t{1}:      [{3}]\r\n//\t{1}:\r\n//\t{1}:   To {4}\r\n//\t{1}:      [{5}]\r\n//\r\n",
                                       BackupTimeStamp, process,
                                       sourceObject.DatabaseSchema, sourceObject.Server, zipFile.Filename, zipFile.Path));

            string[] tablenames = sourceCmd.RetrieveTableNames(schema);

            try
            {
                Process("Backing up " + backupServerDatabase + ".");

                ZipFile.DeflateTableNames();

                if (tablenames.Length == 0 || !BackupTableDependencies() || backupTableDependencies.Rows.Count <= 1)
                {
                    Memo("NONE", string.Format("{0}: {1, 10} There are no Tables to backup\r\n", process, "NONE"));
                    xcount = tablenames.Length;
                }

                else
                {
                    Abort = false;

                    for (int i = 0; i < tablenames.Length && !Abort; i++)
                    {
                        backupObject.FileName = tablenames[i];

                        if (backupObject.ObjectName.ToLower() != veTableDependencies.ToLower() &&
                            backupObject.ObjectName.ToLower() != veTableSchema.ToLower() &&
                            backupObject.ObjectName.ToLower() != veTableDefinition.ToLower())
                        {
                            zipFile.DeflateTableName(backupObject.ObjectName);
                        }
                        else
                        {
                            tablenames[i] = null;
                            count++;
                            Memo("Memo", string.Format("{0}: {1, 10} Table INTENTIONALLY NOT BACKED UP - {2}", process, "-", backupObject.SchemaTable));
                        }
                    }

                    if (count > 0)
                    {
                        Memo("Memo", "");
                    }

                    count = 0;
                    zipFile.DeflateTableName(null);

                    if (backupTableDependencies != null)
                    {
                        StreamWriter stream = ZipFile.DeflateTableScript(veTableDependencies, GetSchemaDefinition(backupTableDependencies));

                        BackupTableDependencies(stream, backupTableDependencies);
                        totals = zipFile.DeflateTableData(veTableDependencies, stream);

                        Memo("Memo", string.Format("{0}: {1,10:n0} Records, {2,10:n0} Bytes ({3,10:n0} Compressed) - {4} (Generated)",
                                                   process, backupTableDependencies.Rows.Count - 1, totals.size, totals.deflated, veTableDependencies));

                        tableCount++;
                    }

                    for (int i = 0; i < tablenames.Length && !Abort; i++)
                    {
                        xcount++;

                        if (tablenames[i] != null)
                        {
                            backupObject.FileName = tablenames[i];

                            Status(backupObject.SchemaTable);
                            Application.DoEvents();

                            string       sql        = GetSchemaDefinition(sourceCmd, backupObject.SchemaTable);
                            StreamWriter backupFile = zipFile.DeflateTableScript(backupObject.ObjectName, sql);

                            count  = BackupTableObject(backupFile, ref recordCount);
                            totals = zipFile.DeflateTableData(backupObject.ObjectName, backupFile);

                            Memo("Memo", string.Format("{0}: {1, 10:n0} Records, {2,10:n0} Bytes ({3,10:n0} Compressed) - {4}",
                                                       process, count, totals.size, totals.deflated, backupObject.TableName));

                            tableCount++;
                            totalRecords += count;
                        }
                    }

                    totals = zipFile.TypeTotal;

                    Memo("Memo", string.Format("\r\n{0}: {1, 10:n0} Records, {2,10:n0} Bytes ({3,10:n0} Compressed) - {4:n0} Tables Backed up",
                                               process, totalRecords, totals.size, totals.deflated, tableCount));
                }
            }
            catch (Exception e)
            {
                Error("VEDataAdminZip.BackupTables: " + backupServerDatabase + "." + schema, e);
                //errors.Add("VEAdminZip.BackupTables Exception: " + backupServerDatabase + "." + schema);
            }
            finally
            {
                if (xcount < tablenames.Length)
                {
                    Error(string.Format("{0}: {1, 10} Only {2:n0} of {3:n0} Tables Processed", process, "", xcount, tablenames.Length));
                }

                else if (totals != null)
                {
                    string text = string.Format("{0}: {1, 48:n1}% {2, 12} {3}\r\n",
                                                process, totals.size > 0 ? 100.0 * totals.deflated / totals.size : 0.0,
                                                "**", Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime));

                    if (!Abort)
                    {
                        Memo("Memo", text);
                    }
                    else
                    {
                        Error(text);
                    }
                }

                ActiveSchema = null;
                Process("");
                Status("");
            }

            return(totals);
        }
コード例 #18
0
        /// <summary>Restores all schema tables, procedures and functions from content found in the specified restoration folder</summary>
        public void RestoreSchema(VEDelegate taskCompletion)
        {
            DateTime startTime = DateTime.Now;

            Memo("Memo", string.Format("/*\r\n**\t{0}\r\n**\tRestore Schema {1} - All Objects\r\n*/\r\n",
                                       BackupTimeStamp, targetObject.DatabaseSchema));

            DropTables();

            if (!Abort)
            {
                RestoreProcedures();
            }

            if (!Abort)
            {
                RestoreFunctions();
            }

            if (!Abort)
            {
                RestoreTables(taskCompletion);
            }

            Memo("Memo", string.Format("/*\r\n**\tRestore Schema {0} - All  Objects: {1}\r\n*/\r\n",
                                       targetObject.DatabaseSchema, abort ? "ABORTED" : VETimeStamp.ElapsedTime(startTime)));
        }
コード例 #19
0
        protected override Totals BackupStoredObjects(string type, string schema)
        {
            DateTime startTime = DateTime.Now;

            ActiveSchema = schema;

            Memo("Memo", string.Format("//\r\n//\t{0}\r\n//\tBackup Schema {1}: From {2}...\r\n" +
                                       "//\tBackup Schema {1}:   To [{3}].{4}...\r\n//\r\n",
                                       BackupTimeStamp, type,
                                       sourceObject.ServerIDDatabaseSchema, backupObject.ServerID, backupObject.Paths[type]));

            Status(string.Format("Backing-up {0} to {1}", type, backupObject.Paths[type]));

            try
            {
                objectCount = objectSize = 0;
                Abort       = false;

                string[] objectNames = type == "Procedures" ? sourceCmd.RetrieveUserProcedures(schema)
                                                                                                                        : sourceCmd.RetrieveFunctionNames(schema);

                if (objectNames.Length == 0)
                {
                    Memo("NONE", string.Format("Backup Schema {0}: {1, 7} There are no {0} to backup", type, "NONE"));
                }
                else
                {
                    foreach (string name in objectNames)
                    {
                        if (name.IndexOf(schema + ".") == 0)
                        {
                            objectCount++;
                            backupObject.ScriptName = name;
                            objectSize += BackupStoredObject(type);

                            if (Abort)
                            {
                                break;
                            }
                        }
                    }

                    if (objectCount > 0)
                    {
                        Memo("Memo", string.Format("\r\nBackup Schema {0}: {1, 7:n0} {0} Copied - {2:n0} Bytes", type, objectCount, objectSize));
                    }
                    else
                    {
                        Memo("NONE", string.Format("Backup Schema {0}: {1, -7} There are no Schema-qualified {0} to backup", type, "NONE"));
                    }
                }
            }
            catch (Exception e)
            {
                Memo("Memo", string.Format("\r\nBackup Schema {0}: {1,7} {2}\r\n", type, "ERROR", e.Message));
            }
            finally
            {
                Memo("Memo", string.Format("Backup Schema {0}: {1, 7} {2}\r\n", type, "**", Abort ? "Operation Aborted" : VETimeStamp.ElapsedTime(startTime)));
                Status("");

                ActiveSchema = null;
            }

            return(null);
        }