private (string resultFileName, string resultContent) GenerateOptionsToCommand() { RemoveCommandOptions("--host"); RemoveCommandOptions("--h"); RemoveCommandOptions("--port"); RemoveCommandOptions("--P"); RemoveCommandOptions("--user"); RemoveCommandOptions("--u"); RemoveCommandOptions("--password"); RemoveCommandOptions("--P"); RemoveCommandOptions("--database"); RemoveCommandOptions("--D"); var now = DateTime.Now; var defaultBackupSqlName = $"databases_{Database}_{now:yyyy_MM_dd_HH_mm_ss}.bak"; var dumpFile = Path.Join(DackupContext.Current.TmpPath, defaultBackupSqlName); AddCommandOptions("-S", Host + "," + Port); if (!CommandOptions.ContainsKey("-E")) { AddCommandOptions("-U", UserName); AddCommandOptions("-P", Password); } AddCommandOptions("-Q", $"BACKUP DATABASE [{Database}] TO DISK = N'{dumpFile}'"); var sb = new StringBuilder(); foreach (var key in CommandOptions.Keys) { var value = CommandOptions[key]; sb.Append(string.IsNullOrWhiteSpace(value) ? $" {key} " : $" {key} {value} "); } return(dumpFile, sb.ToString()); }
private (string resultFileName, string resultContent) GenerateOptionsToCommand() { this.RemoveCommandOptions("--out"); // only support --archive option this.RemoveCommandOptions("--host"); this.RemoveCommandOptions("--port"); this.RemoveCommandOptions("--username"); this.RemoveCommandOptions("--password"); var now = DateTime.Now; var defaultBackupFileName = $"databases_{Database}_{now:yyyy_MM_dd_HH_mm_ss}.gz"; var dumpFile = Path.Join(DackupContext.Current.TmpPath, defaultBackupFileName); this.AddCommandOptions("--host", this.Host); this.AddCommandOptions("--port", this.Port.ToString()); this.AddCommandOptions("--username", this.UserName); this.AddCommandOptions("--password", this.Password); if (!CommandOptions.ContainsKey("--db")) { this.AddCommandOptions("--db", this.Database); } if (!CommandOptions.ContainsKey("--gzip")) { this.AddCommandOptions("--gzip", ""); } if (!CommandOptions.ContainsKey("--archive")) { dumpFile = Path.Join(DackupContext.Current.TmpPath, defaultBackupFileName); this.AddCommandOptions("--archive", dumpFile); } else { dumpFile = Path.Join(DackupContext.Current.TmpPath, $"{now:yyyy_MM_dd_HH_mm_ss}_{CommandOptions["--archive"]}"); this.AddCommandOptions("--archive", dumpFile); } var sb = new StringBuilder(); foreach (var key in CommandOptions.Keys) { var value = CommandOptions[key]; if (string.IsNullOrWhiteSpace(value)) { sb.Append($" {key} "); } else { if (key.StartsWith("--")) { sb.Append($" {key}={value} "); } else { sb.Append($" {key} {value} "); } } } return(dumpFile, sb.ToString()); }
private (string resultFileName, string resultContent) GenerateOptionsToCommand() { this.RemoveCommandOptions("--host"); this.RemoveCommandOptions("--h"); this.RemoveCommandOptions("--port"); this.RemoveCommandOptions("--p"); this.RemoveCommandOptions("--username"); this.RemoveCommandOptions("--U"); var now = DateTime.Now; var defaultBackupFileName = $"databases_{Database}_{now:yyyy_MM_dd_HH_mm_ss}.backup"; var dumpFile = Path.Join(DackupContext.Current.TmpPath, defaultBackupFileName); this.AddCommandOptions("--host", this.Host); this.AddCommandOptions("--port", this.Port.ToString()); this.AddCommandOptions("--username", this.UserName); if (!CommandOptions.ContainsKey("--format") && !CommandOptions.ContainsKey("-F")) { this.AddCommandOptions("--format", "custom"); } if (!CommandOptions.ContainsKey("--compress") && !CommandOptions.ContainsKey("-Z")) { this.AddCommandOptions("--compress", "6"); } if (!CommandOptions.ContainsKey("--dbname") && !CommandOptions.ContainsKey("-d")) { this.AddCommandOptions("--dbname", this.Database); } if (!CommandOptions.ContainsKey("--file") && !CommandOptions.ContainsKey("-f")) { dumpFile = Path.Join(DackupContext.Current.TmpPath, defaultBackupFileName); this.AddCommandOptions("--file", dumpFile); } else { if (CommandOptions.ContainsKey("--file")) { dumpFile = Path.Join(DackupContext.Current.TmpPath, $"{now:yyyy_MM_dd_HH_mm_ss}_{CommandOptions["--file"]}"); this.AddCommandOptions("--file", dumpFile); } else if (CommandOptions.ContainsKey("-f")) { dumpFile = Path.Join(DackupContext.Current.TmpPath, $"{now:yyyy_MM_dd_HH_mm_ss}_{CommandOptions["-f"]}"); this.AddCommandOptions("-f", dumpFile); } } var sb = new StringBuilder(); foreach (var key in CommandOptions.Keys) { var value = CommandOptions[key]; if (string.IsNullOrWhiteSpace(value)) { sb.Append($" {key} "); } else { if (key.StartsWith("--")) { sb.Append($" {key}={value} "); } else { sb.Append($" {key} {value} "); } } } return(dumpFile, sb.ToString()); }