Changed mysqldump arguments and added a filesystem dump path.

This commit is contained in:
flash 2019-02-11 15:16:55 +01:00
parent b149ee5937
commit 0d119eb9a6
2 changed files with 35 additions and 18 deletions

View file

@ -2,19 +2,8 @@
{
public class Config
{
public StorageMethod StorageMethod { get; set; } = StorageMethod.GoogleDrive;
public string GoogleClientId { get; set; }
public string GoogleClientSecret { get; set; }
public string GoogleBackupDirectory { get; set; } = @"Backups";
// these should not be edited in the xml file
public string GoogleAccessToken { get; set; }
public string GoogleTokenType { get; set; }
public long? GoogleTokenExpires { get; set; }
public string GoogleRefreshToken { get; set; }
public string GoogleTokenIssued { get; set; }
public StorageMethod StorageMethod { get; set; } = StorageMethod.Sftp;
public string SftpHost { get; set; }
public ushort SftpPort { get; set; }
public string SftpUsername { get; set; }
@ -23,6 +12,8 @@
public string SftpBackupDirectoryPath { get; set; }
public string SftpTrustedHost { get; set; }
public string FileSystemPath { get; set; } = @"backups";
public string MySqlDumpPathWindows { get; set; } = @"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe";
public string MySqlDumpPath { get; set; } = @"mysqldump";
public string MySqlHost { get; set; } = @"localhost";

View file

@ -148,6 +148,11 @@ namespace BackupManager
mre.WaitOne();
}
break;
case StorageMethod.FileSystem:
if (!Directory.Exists(Config.FileSystemPath))
Directory.CreateDirectory(Config.FileSystemPath);
break;
}
GetBackupStorage();
@ -247,10 +252,17 @@ namespace BackupManager
{
Log($@"Uploading '{name}'...");
switch (BackupStorage)
switch (Config.StorageMethod)
{
case string scpName:
SFTP.UploadFile(stream, scpName + @"/" + name);
case StorageMethod.Sftp:
SFTP.UploadFile(stream, (BackupStorage as string) + @"/" + name);
break;
case StorageMethod.FileSystem:
string filename = Path.Combine(BackupStorage as string, name);
using (FileStream fs = File.OpenWrite(filename))
stream.CopyTo(fs);
break;
}
@ -329,16 +341,26 @@ namespace BackupManager
sw.WriteLine(@"[client]");
sw.WriteLine($@"user={Config.MySqlUser}");
sw.WriteLine($@"password={Config.MySqlPass}");
sw.WriteLine(@"default-character-set=utf8");
sw.WriteLine(@"default-character-set=utf8mb4");
}
// should we use --result-file ?
StringBuilder mysqldumpArgs = new StringBuilder();
mysqldumpArgs.AppendFormat(@"--defaults-file={0} ", tmpFile);
mysqldumpArgs.Append(@"--single-transaction ");
mysqldumpArgs.Append(@"--tz-utc --triggers ");
mysqldumpArgs.Append(@"--routines --hex-blob ");
mysqldumpArgs.Append(@"--add-locks --order-by-primary ");
mysqldumpArgs.Append(@"-l -Q -q -B "); // lock, quote names, quick, databases list
mysqldumpArgs.Append(Config.MySqlDatabases);
Process p = Process.Start(new ProcessStartInfo
{
FileName = IsWindows ? Config.MySqlDumpPathWindows : Config.MySqlDumpPath,
RedirectStandardError = false,
RedirectStandardInput = false,
RedirectStandardOutput = true,
Arguments = $@"--defaults-file={tmpFile} --add-locks -l --order-by-primary -B {Config.MySqlDatabases}",
Arguments = mysqldumpArgs.ToString(),
UseShellExecute = false,
CreateNoWindow = true,
});
@ -383,6 +405,10 @@ namespace BackupManager
SFTP.CreateDirectory(directory);
}
break;
case StorageMethod.FileSystem:
BackupStorage = name ?? Config.FileSystemPath;
break;
}
}