Esempio n. 1
0
        public async static Task<string> GenerateScriptShrink(ModelBackupSchedule _databaseSchedule)
        {
            try
            {
                string _fileNameFullScript = null;
                _fileNameFullScript = _databaseSchedule.Databases.Directory + @"/" + _databaseSchedule.Directory + @"/" + "Shrink" + _databaseSchedule.Databases.DatabaseName + ".sql";
                string script = $"USE [{_databaseSchedule.Databases.DatabaseName}]" + "\n";
                script += $"DBCC SHRINKFILE (CeltaBSYoguty_log, 0, TRUNCATEONLY);";

                if (await SystemFileHelps.FileExist(_fileNameFullScript))
                {
                    return _fileNameFullScript;
                }
                else
                {
                    if(await SystemFileHelps.CreateFile(_fileNameFullScript, script, false))
                        return _fileNameFullScript;
                }
                return _fileNameFullScript;
            }
            catch (Exception err)
            {
                return "Error: " + err.Message;
            }
        }
Esempio n. 2
0
        public async static Task<string> GenerateScriptBackup(ModelBackupSchedule _databaseSchedule)
        {
            try
            {
                string fileNameFullScript = _databaseSchedule.Databases.Directory + @"/" +_databaseSchedule.Directory +@"/"
                + _databaseSchedule.Databases.DatabaseName + _databaseSchedule.DateHourExecution.ToShortTimeString() + ".sql";
                
                
                string backupName;
                if (_databaseSchedule.Type == ServicesCeltaWare.Model.Enum.BackuypType.Full)
                    backupName = $"{_databaseSchedule.Databases.DatabaseName}BackupFull.bak";
                else if (_databaseSchedule.Type == ServicesCeltaWare.Model.Enum.BackuypType.Diferential)
                    backupName = $"{_databaseSchedule.Databases.DatabaseName}BackupDiff{_databaseSchedule.DateHourExecution.Hour.ToString() + _databaseSchedule.DateHourExecution.Minute.ToString()}.bak";
                else
                    backupName = $"{_databaseSchedule.Databases.DatabaseName}BackupIncremetalLog{_databaseSchedule.DateHourExecution.Hour.ToString() + _databaseSchedule.DateHourExecution.Minute.ToString()}.bak";
               
    
               string commandBackup = $"docker exec -i {_databaseSchedule.Databases.ConteinerName} /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P {_databaseSchedule.CustomerProduct.LoginPassword}  -i /var/opt/mssql/{_databaseSchedule.Directory}/{_databaseSchedule.Databases.DatabaseName + _databaseSchedule.DateHourExecution.ToShortTimeString()}.sql";

                string scriptBackup; 
                if (_databaseSchedule.Type == ServicesCeltaWare.Model.Enum.BackuypType.Full)
                {
                    scriptBackup = $"BACKUP DATABASE [{_databaseSchedule.Databases.DatabaseName}] TO  DISK = N\'/var/opt/mssql/{_databaseSchedule.Directory}/{backupName}\'";
                    scriptBackup += $" WITH NOFORMAT, INIT,  NAME = N'{backupName}-Banco de Dados Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION,  STATS = 10";
                }

                else if(_databaseSchedule.Type == ServicesCeltaWare.Model.Enum.BackuypType.Diferential)
                {                  
                    scriptBackup = $"BACKUP DATABASE [{_databaseSchedule.Databases.DatabaseName}] TO  DISK = N\'/var/opt/mssql/{_databaseSchedule.Directory}/{backupName}\'";
                    scriptBackup += $" WITH DIFFERENTIAL, NOFORMAT, INIT,  NAME = N'{backupName}-Banco de Dados Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION,  STATS = 10";
                }

                else
                {
                    scriptBackup = $"BACKUP LOG [{_databaseSchedule.Databases.DatabaseName}] TO  DISK = N\'/var/opt/mssql/{_databaseSchedule.Directory}/{backupName}\'";
                    scriptBackup += $" WITH FORMAT, INIT,  NAME = N'{backupName}-Banco de Dados Backup', SKIP, NOREWIND, NOUNLOAD, COMPRESSION,  STATS = 10";
                }

                if (await SystemFileHelps.FileExist(fileNameFullScript))
                { 
                    return commandBackup;
                }
                else
                {
                    await SystemFileHelps.CreateFile(fileNameFullScript, scriptBackup, false);
                        return "back";                    
                }

               
            }
            catch(Exception err)
            {
                return "Error" + err.Message;
            }
        }
Esempio n. 3
0
        private static async Task<bool> CreateFile(ServicesCeltaWare.Model.Enum.ValidateType _validateType, string backupName, string _fileNameFullScript, ModelBackupSchedule _backupSchedule)
        {
            string scriptBackup = null;
            if (_validateType == ServicesCeltaWare.Model.Enum.ValidateType.LabelOnly)
            {
                scriptBackup = $"Restore LabelOnly from Disk =  \'/var/opt/mssql/{_backupSchedule.Directory}/{backupName}\'";
            }
            else if (_validateType == ServicesCeltaWare.Model.Enum.ValidateType.VerifyOnly)
            {
                scriptBackup = $"Restore VerifyOnly from Disk =  \'/var/opt/mssql/{_backupSchedule.Directory}/{backupName}\'";
            }


            if (await SystemFileHelps.FileExist(_fileNameFullScript))
            {
                return true;
            }
            else
            {
                await SystemFileHelps.CreateFile(_fileNameFullScript, scriptBackup, false);
                return false;
            }
        }