Exemple #1
0
        public static List <CommandLogValue> GetLastExecutionCommandLogs(string commandType)
        {
            string sql = "SELECT [ID],[DatabaseName],[SchemaName],[ObjectName],";

            sql += "[ObjectType],[IndexName],[IndexType],[StatisticsName],[PartitionNumber],";
            sql += "[ExtendedInfo],[Command],[CommandType],[StartTime],[EndTime],[ErrorNumber]";
            sql += ",[ErrorMessage] FROM CommandLog WHERE CommandType = @CommandType Order By Id Desc";
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@CommandType", commandType));
            List <CommandLogValue> values = new List <CommandLogValue>();

            DatabaseManager manager = new DatabaseManager();
            List <object>   objects = manager.ExecuteQuery(sql, QueryMode.Reader, parameters.ToArray(), new CommandLogValue()) as List <object>;

            if (objects != null)
            {
                foreach (object obj in objects)
                {
                    CommandLogValue value = obj as CommandLogValue;
                    if (obj != null)
                    {
                        values.Add(value);
                    }
                }
            }
            return(values);
        }
Exemple #2
0
        public static string CompressLastBackup()
        {
            List <CommandLogValue> values = Utility.GetLastExecutionCommandLogs("BACKUP_DATABASE");

            if (values.Count > 0)
            {
                CommandLogValue value          = values[0];
                string          backupFilePath = Utility.GetBackupFilePath(value.Command);
                if (!String.IsNullOrEmpty(backupFilePath))
                {
                    string compressedPath = Utility.Compress(new FileInfo(backupFilePath));
                    // compression successful
                    // delete the uncompressed file
                    if (!String.IsNullOrEmpty(compressedPath))
                    {
                        File.Delete(backupFilePath);
                    }
                    return(compressedPath);
                }
            }
            return(null);
        }