Beispiel #1
0
        public override string Query()
        {
            LogOptions.GetLogger().Info("Starting to run mysqldump of database");
            var settings   = BackupSettings.GetInstance();
            var executable = settings.Executable;
            var arguments  = $"-u {settings.User} -p{settings.Password} {settings.Database}";

            LogOptions.GetLogger().Info("Starting dump {executable} {arguments}", executable, arguments);
            try
            {
                var processStartInfo = new ProcessStartInfo
                {
                    FileName               = executable,
                    Arguments              = arguments,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    CreateNoWindow         = true,
                    UseShellExecute        = false
                };
                var p = Process.Start(processStartInfo);
                var standardOutput = p?.StandardOutput.ReadToEnd();
                p?.WaitForExit();
                return(standardOutput);
            }
            catch (Exception e)
            {
                LogOptions.GetLogger().Fatal(e, "Exception in dump mysql database {message}", e.Message);
                return(string.Empty);
            }
        }
Beispiel #2
0
 protected override void OnExecuting()
 {
     foreach (var extraPath in BackupSettings.GetInstance().CopyBackupsTo)
     {
         var destinationPath = Path.Combine(extraPath, _subPath);
         CopyFile(destinationPath);
     }
 }
        protected override void OnExecuting()
        {
            //Abort backup if only when skywin is running and not currently running
            if (BackupSettings.GetInstance().OnlyBackupWhenSkyWinIsRunning && !new IsSkywinRunningQuery().Query())
            {
                LogOptions.GetLogger().Info("Backup only when skywin is running - it's not right now - aborting");
                return;
            }

            var sqlData = new DumpMySqlDatabaseQuery().Query();
            if (string.IsNullOrWhiteSpace(sqlData))
            {
                LogOptions.GetLogger().Warn("Unable to dump sql database into string {output}", sqlData);
                return;
            }

            var dateTime = DateTime.Now;
            var subPath = Path.Combine(dateTime.Year.ToString(), dateTime.Month.ToString(), dateTime.Day.ToString(),
                DateTime.Now.ToString("s").Replace(":", "-") + ".sql");

            var initialFile = Path.Combine(BackupSettings.GetInstance().SaveBackupPath, subPath);
            LogOptions.GetLogger().Info("Initial backup will be saved into {filepath}", initialFile);

            try
            {
                var fi = new FileInfo(initialFile);
                if (!fi?.Directory?.Exists ?? true)
                {
                    LogOptions.GetLogger().Info("Directory path for file doesnt exists creating it");
                    fi?.Directory?.Create();
                }

                LogOptions.GetLogger().Info("Saving backup file");
                File.WriteAllText(initialFile, sqlData);
                LogOptions.GetLogger().Info("Saved backup file");

                if (BackupSettings.GetInstance().CopyBackupsTo?.Count > 0)
                    new CopyBackupFileIntoExtraLocationsCommand(initialFile, subPath).Execute();
            }
            catch (Exception e)
            {
                LogOptions.GetLogger().Fatal(e, "Exception in save initial file {message}", e.Message);
            }
        }