Beispiel #1
0
        private static void DoRestore()
        {
            if (!_command.Restore)
            {
                return;
            }

            Consoler.Write("Restore requested...");
            RestoreDatabase.Execute(_server, _command.Folder, _command.DatabaseName);
        }
Beispiel #2
0
 public static void RestoreDatabaseFromFolder(Server server, string databaseName, string backupPath)
 {
     Consoler.Write(backupPath);
     foreach (var file in Directory.EnumerateFiles(backupPath, "*.bak").OrderBy(x => x))
     {
         try
         {
             Consoler.Write(file);
             Execute(server, databaseName, file);
         }
         catch (Exception ex)
         {
             Consoler.Warn("bak restore failed", backupPath);
             Consoler.Error(ex.ToString());
         }
     }
 }
Beispiel #3
0
        private static void DoBackup()
        {
            if (!_command.Backup)
            {
                return;
            }

            Consoler.Write("Backup requested...");
            BackupDatabase.Execute(_server, _command.DatabaseName, _command.NameOfCredentials, _command.BackFullPath);

            if (_command.ZipBackup)
            {
                var dir = $"{Path.GetDirectoryName(_command.BackFullPath)}\\backup_{_command.DatabaseName}_{DateTime.Now.ToString("yyyyMMdd")}";
                Directory.CreateDirectory(dir);
                File.Move(_command.BackFullPath, Path.Combine(dir, Path.GetFileName(_command.BackFullPath))); // add extract folder name in for zipping, move file into it then zip it
                ZipFile.CreateFromDirectory(dir, _command.BackFullPath.Replace(".bak", ".zip"), CompressionLevel.Optimal, false);
                Directory.Delete(dir, true);
            }
        }
Beispiel #4
0
 public static void ShowHelpAndExit(bool noPrompt = false)
 {
     Consoler.Title("Usage:");
     Consoler.Write("/help\t\t\tShow help");
     Consoler.Write("");
     Consoler.Write("Example:");
     Consoler.Write("");
     Consoler.Write(@"DatabaseMinder.Runner.exe /e /p /b /z /d DatabaseMinder /f c:\temp");
     Consoler.Write("");
     Consoler.Write("Arguments:");
     Consoler.Write("");
     Consoler.Write("\t/e EnableArgsModeViaConfig - true or false --> use config args or command line args");
     Consoler.Write("\t/p PromptsEnabled - true or false -->  pause and show prompts on the console (or skip)");
     Consoler.Write("\t/r Restore - true or false --> Restore database");
     Consoler.Write("\t/b Backup - true or false --> Backup database");
     Consoler.Write("\t/d DatabaseName - the database name to back or restore");
     Consoler.Write("\t/s ServerName - leave blank for localhost");
     Consoler.Write("\t/f Folder - folder to use for backup,restore,zip");
     //Consoler.Write("\t/c ConnectionString - for backups / restore");
     Consoler.Write("\t/z ZipBackup -  true or false --> after backup zip the .bak file");
     ShowPauseAndExit(noPrompt);
 }