public static void all(string backup_file_prefix, bool overwrite) { BinaryDump dump; string output_file_name; SQLServer m_server = SQLServer.Instance; foreach(string database_name in m_server.databaseNames()) { try { Logger.Instance.write("Dumping database " + database_name); output_file_name = Path.ChangeExtension(backup_file_prefix + "-" + database_name, "bak"); dump = new BinaryDump(database_name, output_file_name); dump.overwrite = overwrite; dump.dump(); } catch (CannotBackupTemporaryDatabase) { Logger.Instance.write("Cannot backup tempdb. Ignoring"); continue; } } }
public static int Main(string[] args) { String output_file_name; // Parse command line options options = new Options(); CommandLineParser parser = new CommandLineParser(options); parser.Parse(); if (options.help) { Console.Error.WriteLine(parser.UsageInfo.ToString(78, false)); return 0; } if (parser.HasErrors) { Console.Error.WriteLine(parser.UsageInfo.ToString(78, true)); return -1; } Logger.Instance.enabled = options.verbose; try { if (options.all_databases) { if (options.output_file_name.isEmpty()) { Console.WriteLine(@"Syntax Error: Missing output file name"); Console.WriteLine(parser.UsageInfo.ToString(78, true)); return -1; } sqlconnect(); BinaryDump.all(options.output_file_name, options.overwrite); return 0; } if (options.list_databases) { sqlconnect(); SQLInfo.printDatabaseNames(); return 0; } // Start dump process if (options.database_name.Length != 0) { sqlconnect(); if (options.binary_dump) { output_file_name = Path.ChangeExtension(options.output_file_name, "bak"); BinaryDump dump = new BinaryDump(options.database_name, output_file_name); dump.overwrite = options.overwrite; dump.dump(); } else if (options.binary_dump){ output_file_name = Path.ChangeExtension(options.output_file_name, "sql"); ScriptDump dump = new ScriptDump(options.database_name, output_file_name); dump.dump(); } return 0; } } catch (ErrorCreatingOutputFile e) { Console.Error.Write(e.ToString()); return 1; } catch (ConnectionFailureException e) { Console.Error.Write(e.Message.ToString()); Console.Error.Write("See Trouble.TXT for possible solutions."); return 2; } Console.Error.WriteLine(parser.UsageInfo.ToString(78, false)); return 0; }