Retarget to .NET 6.0
This commit is contained in:
parent
cbe982ba77
commit
1f9ac0552a
4 changed files with 37 additions and 42 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
namespace BackupManager
|
namespace BackupManager {
|
||||||
{
|
public class Config {
|
||||||
public class Config
|
|
||||||
{
|
|
||||||
public string FileSystemPathV2 { get; set; }
|
public string FileSystemPathV2 { get; set; }
|
||||||
|
|
||||||
public string MySqlDumpPathWindows { get; set; } = @"C:\Program Files\MariaDB 10.3\bin\mysqldump.exe";
|
public string MySqlDumpPathWindows { get; set; } = @"C:\Program Files\MariaDB 10.3\bin\mysqldump.exe";
|
||||||
|
|
|
@ -15,7 +15,7 @@ using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace BackupManager {
|
namespace BackupManager {
|
||||||
public static class Program {
|
public static class Program {
|
||||||
public readonly static Stopwatch sw = new Stopwatch();
|
public readonly static Stopwatch sw = new();
|
||||||
|
|
||||||
private const string CONFIG_NAME = @"FlashiiBackupManager.v1.xml";
|
private const string CONFIG_NAME = @"FlashiiBackupManager.v1.xml";
|
||||||
|
|
||||||
|
@ -39,15 +39,15 @@ namespace BackupManager {
|
||||||
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), @"Backups")
|
? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), @"Backups")
|
||||||
: Config.FileSystemPathV2;
|
: Config.FileSystemPathV2;
|
||||||
|
|
||||||
public static bool Headless;
|
private static bool Headless;
|
||||||
|
|
||||||
public static string WindowsToUnixPath(this string path) {
|
public static string WindowsToUnixPath(this string path) {
|
||||||
return IsWindows ? path.Replace('\\', '/') : path;
|
return IsWindows ? path.Replace('\\', '/') : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Stream ToXml(this object obj, bool pretty = false) {
|
public static Stream ToXml(this object obj, bool pretty = false) {
|
||||||
MemoryStream ms = new MemoryStream();
|
MemoryStream ms = new();
|
||||||
XmlSerializer xs = new XmlSerializer(obj.GetType());
|
XmlSerializer xs = new(obj.GetType());
|
||||||
|
|
||||||
using(XmlWriter xw = XmlWriter.Create(ms, new XmlWriterSettings { Indent = pretty }))
|
using(XmlWriter xw = XmlWriter.Create(ms, new XmlWriterSettings { Indent = pretty }))
|
||||||
xs.Serialize(xw, obj);
|
xs.Serialize(xw, obj);
|
||||||
|
@ -60,20 +60,20 @@ namespace BackupManager {
|
||||||
if(xml.CanSeek)
|
if(xml.CanSeek)
|
||||||
xml.Seek(0, SeekOrigin.Begin);
|
xml.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
XmlSerializer xs = new XmlSerializer(typeof(T));
|
XmlSerializer xs = new(typeof(T));
|
||||||
return (T)xs.Deserialize(xml);
|
return (T)xs.Deserialize(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveConfig() {
|
public static void SaveConfig() {
|
||||||
Log(@"Saving configuration...");
|
Log(@"Saving configuration...");
|
||||||
using (FileStream fs = new FileStream(ConfigPath, FileMode.Create, FileAccess.Write))
|
using FileStream fs = new(ConfigPath, FileMode.Create, FileAccess.Write);
|
||||||
using (Stream cs = Config.ToXml(true))
|
using Stream cs = Config.ToXml(true);
|
||||||
cs.CopyTo(fs);
|
cs.CopyTo(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadConfig() {
|
public static void LoadConfig() {
|
||||||
Log(@"Loading configuration...");
|
Log(@"Loading configuration...");
|
||||||
using (FileStream fs = File.OpenRead(ConfigPath))
|
using FileStream fs = File.OpenRead(ConfigPath);
|
||||||
Config = FromXml<Config>(fs);
|
Config = FromXml<Config>(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ namespace BackupManager {
|
||||||
|
|
||||||
Log(@"Fetching database list...");
|
Log(@"Fetching database list...");
|
||||||
|
|
||||||
MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder {
|
MySqlConnectionStringBuilder connStr = new() {
|
||||||
Server = Config.MySqlHost,
|
Server = Config.MySqlHost,
|
||||||
UserID = Config.MySqlUser,
|
UserID = Config.MySqlUser,
|
||||||
Password = Config.MySqlPass,
|
Password = Config.MySqlPass,
|
||||||
|
@ -104,16 +104,16 @@ namespace BackupManager {
|
||||||
SslMode = MySqlSslMode.None,
|
SslMode = MySqlSslMode.None,
|
||||||
};
|
};
|
||||||
|
|
||||||
List<string> databases = new List<string>();
|
List<string> databases = new();
|
||||||
string[] exclude = Config.MySqlExcludeDatabases.Split(' ');
|
string[] exclude = Config.MySqlExcludeDatabases.Split(' ');
|
||||||
|
|
||||||
using (MySqlConnection conn = new MySqlConnection(connStr.ToString())) {
|
using(MySqlConnection conn = new(connStr.ToString())) {
|
||||||
conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
using(MySqlCommand comm = new(@"SET NAMES 'utf8mb4';", conn))
|
using(MySqlCommand comm = new(@"SET NAMES 'utf8mb4';", conn))
|
||||||
comm.ExecuteNonQuery();
|
comm.ExecuteNonQuery();
|
||||||
|
|
||||||
using(MySqlCommand comm = new MySqlCommand(@"SHOW DATABASES;", conn))
|
using(MySqlCommand comm = new(@"SHOW DATABASES;", conn))
|
||||||
using(MySqlDataReader read = comm.ExecuteReader()) {
|
using(MySqlDataReader read = comm.ExecuteReader()) {
|
||||||
while(read.Read()) {
|
while(read.Read()) {
|
||||||
string database = read.GetString(0);
|
string database = read.GetString(0);
|
||||||
|
@ -131,13 +131,13 @@ namespace BackupManager {
|
||||||
string archivePath = Path.GetTempFileName();
|
string archivePath = Path.GetTempFileName();
|
||||||
|
|
||||||
using(FileStream fs = File.OpenWrite(archivePath))
|
using(FileStream fs = File.OpenWrite(archivePath))
|
||||||
using (ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Create)) {
|
using(ZipArchive archive = new(fs, ZipArchiveMode.Create)) {
|
||||||
Log(@"Database backup...");
|
Log(@"Database backup...");
|
||||||
|
|
||||||
string sqldefaults = Path.GetTempFileName();
|
string sqldefaults = Path.GetTempFileName();
|
||||||
|
|
||||||
using(FileStream sqlConfFs = File.Open(sqldefaults, FileMode.Open, FileAccess.ReadWrite))
|
using(FileStream sqlConfFs = File.Open(sqldefaults, FileMode.Open, FileAccess.ReadWrite))
|
||||||
using (StreamWriter sw = new StreamWriter(sqlConfFs)) {
|
using(StreamWriter sw = new(sqlConfFs)) {
|
||||||
sw.WriteLine(@"[client]");
|
sw.WriteLine(@"[client]");
|
||||||
sw.WriteLine($@"user={Config.MySqlUser}");
|
sw.WriteLine($@"user={Config.MySqlUser}");
|
||||||
sw.WriteLine($@"password={Config.MySqlPass}");
|
sw.WriteLine($@"password={Config.MySqlPass}");
|
||||||
|
@ -232,7 +232,7 @@ namespace BackupManager {
|
||||||
|
|
||||||
string sqldump = Path.GetTempFileName();
|
string sqldump = Path.GetTempFileName();
|
||||||
|
|
||||||
StringBuilder mysqldumpArgs = new StringBuilder();
|
StringBuilder mysqldumpArgs = new();
|
||||||
mysqldumpArgs.AppendFormat(@"--defaults-file={0} ", defaults);
|
mysqldumpArgs.AppendFormat(@"--defaults-file={0} ", defaults);
|
||||||
mysqldumpArgs.Append(@"--single-transaction ");
|
mysqldumpArgs.Append(@"--single-transaction ");
|
||||||
mysqldumpArgs.Append(@"--tz-utc --triggers ");
|
mysqldumpArgs.Append(@"--tz-utc --triggers ");
|
||||||
|
|
|
@ -1,5 +1,2 @@
|
||||||
cwd="$(pwd)"
|
|
||||||
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
||||||
cd "$(dirname "$0")"
|
|
||||||
dotnet run --project BackupManager -c Release -f net6.0 -- -cron
|
dotnet run --project BackupManager -c Release -f net6.0 -- -cron
|
||||||
cd "$cwd"
|
|
||||||
|
|
Reference in a new issue