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