mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Fixed the cleanup of the User config backup files.
Fixed the cleanup of the profile/world backup file in CSM.
This commit is contained in:
parent
3512e36bac
commit
3b2bad7607
20 changed files with 221 additions and 141 deletions
|
|
@ -569,6 +569,9 @@ namespace ServerManagerTool
|
|||
|
||||
SettingsUtils.BackupUserConfigSettings(Config.Default, "userconfig.json", installFolder, backupFolder);
|
||||
SettingsUtils.BackupUserConfigSettings(CommonConfig.Default, "commonconfig.json", installFolder, backupFolder);
|
||||
|
||||
SettingsUtils.DeleteBackupUserConfigFiles("userconfig.json", backupFolder, ServerApp.BACKUP_DELETEINTERVAL);
|
||||
SettingsUtils.DeleteBackupUserConfigFiles("commonconfig.json", backupFolder, ServerApp.BACKUP_DELETEINTERVAL);
|
||||
}
|
||||
|
||||
private void ShutDownApplication()
|
||||
|
|
|
|||
|
|
@ -567,6 +567,7 @@
|
|||
<sys:String x:Key="GlobalSettings_BackupIntervalLabel">Backup Interval:</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_BackupIntervalTooltip">How often to perform the server backup, in hours and minutes (hh:mm). Set to 00:00 to disable.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DeleteOldFilesLabel">Delete Old Backup Files</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DeleteOldFilesTooltip">If enabled, when the auto-backup runs the old backup files will be deleted.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DeleteIntervalLabel">Older Than:</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DeleteIntervalTooltip">How old the backup file must be to be deleted in days.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_BackupWorldSaveLabel">WorldSave Message:</sys:String>
|
||||
|
|
|
|||
|
|
@ -35,8 +35,7 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
public const int MUTEX_TIMEOUT = 5; // 5 minutes
|
||||
public const int MUTEX_ATTEMPTDELAY = 5000; // 5 seconds
|
||||
private const int WRITELOG_ERRORRETRYDELAY = 2000; // 2 seconds
|
||||
private const int BACKUP_DELETEINTERVAL = 7; // 7 days
|
||||
public const int BACKUP_DELETEINTERVAL = 7; // 7 days
|
||||
|
||||
private const int STEAM_MAXRETRIES = 10;
|
||||
private const int RCON_MAXRETRIES = 3;
|
||||
|
|
@ -100,7 +99,7 @@ namespace ServerManagerTool.Lib
|
|||
public bool BackupWorldFile = Config.Default.BackupWorldFile;
|
||||
public bool CheckForOnlinePlayers = Config.Default.ServerShutdown_CheckForOnlinePlayers;
|
||||
public bool SendMessages = Config.Default.ServerShutdown_SendShutdownMessages;
|
||||
public bool DeleteOldServerBackupFiles = false;
|
||||
public bool DeleteOldBackupFiles = Config.Default.AutoBackup_DeleteOldFiles;
|
||||
public int ExitCode = EXITCODE_NORMALEXIT;
|
||||
public bool OutputLogs = false;
|
||||
public bool SendAlerts = false;
|
||||
|
|
@ -1786,7 +1785,7 @@ namespace ServerManagerTool.Lib
|
|||
ExitCode = EXITCODE_NORMALEXIT;
|
||||
}
|
||||
|
||||
public void CheckServerWorldFileExists(ServerProfileSnapshot profile = null)
|
||||
public void CheckServerWorldFileExists(ServerProfileSnapshot profile)
|
||||
{
|
||||
// do nothing if profile is null or SotF
|
||||
if (profile == null || profile.SotFEnabled)
|
||||
|
|
@ -1826,7 +1825,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
}
|
||||
|
||||
public void CreateProfileBackupArchiveFile(ServerProfileSnapshot profile = null)
|
||||
public void CreateProfileBackupArchiveFile(ServerProfileSnapshot profile)
|
||||
{
|
||||
// do nothing if profile is null
|
||||
if (profile == null)
|
||||
|
|
@ -1897,52 +1896,58 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
|
||||
// delete the old backup files
|
||||
try
|
||||
if (DeleteOldBackupFiles)
|
||||
{
|
||||
LogProfileMessage("Delete old profile backup files started...");
|
||||
|
||||
var backupFolder = GetProfileBackupFolder(_profile);
|
||||
var backupFileFilter = $"*{Config.Default.BackupExtension}";
|
||||
var backupDateFilter = DateTime.Now.AddDays(-BACKUP_DELETEINTERVAL);
|
||||
|
||||
var backupFiles = new DirectoryInfo(backupFolder).GetFiles(backupFileFilter).Where(f => f.LastWriteTime < backupDateFilter);
|
||||
foreach (var backupFile in backupFiles)
|
||||
try
|
||||
{
|
||||
try
|
||||
var deleteInterval = Config.Default.AutoBackup_EnableBackup ? Config.Default.AutoBackup_DeleteInterval : BACKUP_DELETEINTERVAL;
|
||||
|
||||
LogProfileMessage("Delete old profile backup files started...");
|
||||
|
||||
var backupFolder = GetProfileBackupFolder(_profile);
|
||||
var backupFileFilter = $"*{Config.Default.BackupExtension}";
|
||||
var backupDateFilter = DateTime.Now.AddDays(-deleteInterval);
|
||||
|
||||
var backupFiles = new DirectoryInfo(backupFolder).GetFiles(backupFileFilter).Where(f => f.LastWriteTime < backupDateFilter);
|
||||
foreach (var backupFile in backupFiles)
|
||||
{
|
||||
LogProfileMessage($"{backupFile.Name} was deleted, last updated {backupFile.CreationTime}.");
|
||||
backupFile.Delete();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
try
|
||||
{
|
||||
LogProfileMessage($"{backupFile.Name} was deleted, last updated {backupFile.CreationTime}.");
|
||||
backupFile.Delete();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogProfileError($"Error deleting old profile backup files.\r\n{ex.Message}", false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogProfileMessage("Delete old profile backup files finished.");
|
||||
}
|
||||
|
||||
// cleanup any backup folders from old backup process
|
||||
try
|
||||
{
|
||||
var backupFolder = GetProfileBackupFolder(_profile);
|
||||
|
||||
var oldBackupFolders = new DirectoryInfo(backupFolder).GetDirectories();
|
||||
foreach (var oldBackupFolder in oldBackupFolders)
|
||||
catch (Exception ex)
|
||||
{
|
||||
oldBackupFolder.Delete(true);
|
||||
LogProfileError($"Error deleting old profile backup files.\r\n{ex.Message}", false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogProfileMessage("Delete old profile backup files finished.");
|
||||
}
|
||||
|
||||
// cleanup any backup folders from old backup process
|
||||
try
|
||||
{
|
||||
var backupFolder = GetProfileBackupFolder(_profile);
|
||||
|
||||
var oldBackupFolders = new DirectoryInfo(backupFolder).GetDirectories();
|
||||
foreach (var oldBackupFolder in oldBackupFolders)
|
||||
{
|
||||
oldBackupFolder.Delete(true);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -1950,7 +1955,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
}
|
||||
|
||||
public void CreateServerBackupArchiveFile(StringBuilder emailMessage, ServerProfileSnapshot profile = null)
|
||||
public void CreateServerBackupArchiveFile(StringBuilder emailMessage, ServerProfileSnapshot profile)
|
||||
{
|
||||
// do nothing if profile is null or SotF
|
||||
if (profile == null || profile.SotFEnabled)
|
||||
|
|
@ -2087,7 +2092,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
|
||||
// delete the old backup files
|
||||
if (DeleteOldServerBackupFiles)
|
||||
if (DeleteOldBackupFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -3096,7 +3101,7 @@ namespace ServerManagerTool.Lib
|
|||
Parallel.ForEach(_profiles.Keys.Where(p => p.EnableAutoBackup), profile => {
|
||||
var app = new ServerApp
|
||||
{
|
||||
DeleteOldServerBackupFiles = Config.Default.AutoBackup_DeleteOldFiles,
|
||||
DeleteOldBackupFiles = Config.Default.AutoBackup_DeleteOldFiles,
|
||||
OutputLogs = true,
|
||||
SendAlerts = true,
|
||||
SendEmails = true,
|
||||
|
|
|
|||
|
|
@ -4815,7 +4815,7 @@ namespace ServerManagerTool.Lib
|
|||
var app = new ServerApp(true)
|
||||
{
|
||||
BackupWorldFile = false,
|
||||
DeleteOldServerBackupFiles = false,
|
||||
DeleteOldBackupFiles = false,
|
||||
SendAlerts = false,
|
||||
SendEmails = false,
|
||||
OutputLogs = false
|
||||
|
|
|
|||
|
|
@ -961,7 +961,7 @@ namespace ServerManagerTool.Lib
|
|||
var serverApp = new ServerApp()
|
||||
{
|
||||
BackupWorldFile = false,
|
||||
DeleteOldServerBackupFiles = false,
|
||||
DeleteOldBackupFiles = false,
|
||||
SendAlerts = false,
|
||||
SendEmails = false,
|
||||
OutputLogs = false
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@
|
|||
</TextBox.Text>
|
||||
</TextBox>
|
||||
|
||||
<CheckBox Grid.Row="0" Grid.Column="2" Margin="5,0,0,0" Content="{DynamicResource GlobalSettings_DeleteOldFilesLabel}" IsChecked="{Binding Config.AutoBackup_DeleteOldFiles, Mode=TwoWay}" ToolTip="{DynamicResource GlobalSettings_UseSmartCopyTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
|
||||
<CheckBox Grid.Row="0" Grid.Column="2" Margin="5,0,0,0" Content="{DynamicResource GlobalSettings_DeleteOldFilesLabel}" IsChecked="{Binding Config.AutoBackup_DeleteOldFiles, Mode=TwoWay}" ToolTip="{DynamicResource GlobalSettings_DeleteOldFilesTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
|
||||
<cctl:AnnotatedSlider Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" Margin="5,0,5,0" Label="{DynamicResource GlobalSettings_DeleteIntervalLabel}" Value="{Binding Config.AutoBackup_DeleteInterval}" Minimum="1" Maximum="1000" SmallChange="1" LargeChange="2" TickFrequency="5" LabelRelativeWidth="Auto" SliderRelativeWidth="15*" SuffixRelativeWidth="Auto" Suffix="{DynamicResource SliderUnits_Days}" ToolTip="{DynamicResource GlobalSettings_DeleteIntervalTooltip}" IsEnabled="{Binding Config.AutoBackup_DeleteOldFiles}"/>
|
||||
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="{DynamicResource GlobalSettings_BackupWorldSaveLabel}" VerticalAlignment="Center"/>
|
||||
|
|
|
|||
|
|
@ -1052,7 +1052,7 @@ namespace ServerManagerTool
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
SendEmails = false,
|
||||
OutputLogs = false,
|
||||
ServerProcess = ServerProcessType.Backup,
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -396,7 +396,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -497,7 +497,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -598,7 +598,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -701,7 +701,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -805,7 +805,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,29 @@
|
|||
<link href="http://arkservermanager.freeforums.net/" />
|
||||
<updated>2021-12-16T00:00:00Z</updated>
|
||||
|
||||
<entry>
|
||||
<id>urn:uuid:A652172B-F29A-4050-8A0C-8A34F6DDF1FA</id>
|
||||
<title>1.1.413 (1.1.413.12)</title>
|
||||
<summary>1.1.413.12</summary>
|
||||
<link href="" />
|
||||
<updated>2021-12-18T00:00:00Z</updated>
|
||||
<content type="xhtml">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
|
||||
<p>
|
||||
<u style="font-size: .9em;">BUGFIX</u>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Fixed the cleanup of the User config backup files.</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</content>
|
||||
<author>
|
||||
<name>bletch</name>
|
||||
<email>bletch1971@hotmail.com</email>
|
||||
</author>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<id>urn:uuid:A652172B-F29A-4050-8A0C-8A34F6DDF1FA</id>
|
||||
<title>1.1.413 (1.1.413.11)</title>
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ namespace ServerManagerTool.Windows
|
|||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
SendEmails = false,
|
||||
OutputLogs = false,
|
||||
ServerProcess = ServerProcessType.Backup,
|
||||
|
|
|
|||
|
|
@ -558,6 +558,9 @@ namespace ServerManagerTool
|
|||
|
||||
SettingsUtils.BackupUserConfigSettings(Config.Default, "userconfig.json", installFolder, backupFolder);
|
||||
SettingsUtils.BackupUserConfigSettings(CommonConfig.Default, "commonconfig.json", installFolder, backupFolder);
|
||||
|
||||
SettingsUtils.DeleteBackupUserConfigFiles("userconfig.json", backupFolder, ServerApp.BACKUP_DELETEINTERVAL);
|
||||
SettingsUtils.DeleteBackupUserConfigFiles("commonconfig.json", backupFolder, ServerApp.BACKUP_DELETEINTERVAL);
|
||||
}
|
||||
|
||||
private void ShutDownApplication()
|
||||
|
|
|
|||
|
|
@ -728,6 +728,7 @@
|
|||
<sys:String x:Key="GlobalSettings_BackupIntervalLabel">Backup Interval:</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_BackupIntervalTooltip">How often to perform the server backup, in hours and minutes (hh:mm). Set to 00:00 to disable.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DeleteOldFilesLabel">Delete Old Backup Files</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DeleteOldFilesTooltip">If enabled, when the auto-backup runs the old backup files will be deleted.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DeleteIntervalLabel">Older Than:</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_DeleteIntervalTooltip">How old the backup file must be to be deleted in days.</sys:String>
|
||||
<sys:String x:Key="GlobalSettings_BackupWorldSaveLabel">WorldSave Message:</sys:String>
|
||||
|
|
|
|||
|
|
@ -35,8 +35,7 @@ namespace ServerManagerTool.Lib
|
|||
|
||||
public const int MUTEX_TIMEOUT = 5; // 5 minutes
|
||||
public const int MUTEX_ATTEMPTDELAY = 5000; // 5 seconds
|
||||
private const int WRITELOG_ERRORRETRYDELAY = 2000; // 2 seconds
|
||||
private const int BACKUP_DELETEINTERVAL = 7; // 7 days
|
||||
public const int BACKUP_DELETEINTERVAL = 7; // 7 days
|
||||
|
||||
private const int STEAM_MAXRETRIES = 10;
|
||||
private const int RCON_MAXRETRIES = 3;
|
||||
|
|
@ -100,7 +99,7 @@ namespace ServerManagerTool.Lib
|
|||
public bool BackupWorldFile = Config.Default.BackupWorldFile;
|
||||
public bool CheckForOnlinePlayers = Config.Default.ServerShutdown_CheckForOnlinePlayers;
|
||||
public bool SendMessages = Config.Default.ServerShutdown_SendShutdownMessages;
|
||||
public bool DeleteOldServerBackupFiles = false;
|
||||
public bool DeleteOldBackupFiles = Config.Default.AutoBackup_DeleteOldFiles;
|
||||
public int ExitCode = EXITCODE_NORMALEXIT;
|
||||
public bool OutputLogs = false;
|
||||
public bool SendAlerts = false;
|
||||
|
|
@ -187,7 +186,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
|
||||
// make a backup of the current profile and config files.
|
||||
CreateProfileBackupArchiveFile();
|
||||
CreateProfileBackupArchiveFile(_profile);
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
return;
|
||||
|
|
@ -198,7 +197,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
|
||||
// make a backup of the current world file.
|
||||
CreateServerBackupArchiveFile(emailMessage);
|
||||
CreateServerBackupArchiveFile(emailMessage, _profile);
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
return;
|
||||
|
|
@ -256,7 +255,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
|
||||
// make a backup of the current profile and config files.
|
||||
CreateProfileBackupArchiveFile();
|
||||
CreateProfileBackupArchiveFile(_profile);
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
return;
|
||||
|
|
@ -264,7 +263,7 @@ namespace ServerManagerTool.Lib
|
|||
if (BackupWorldFile)
|
||||
{
|
||||
// make a backup of the current world file.
|
||||
CreateServerBackupArchiveFile(null);
|
||||
CreateServerBackupArchiveFile(null, _profile);
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
return;
|
||||
|
|
@ -1161,7 +1160,7 @@ namespace ServerManagerTool.Lib
|
|||
emailMessage.AppendLine($"Server Manager version: {App.Instance.Version}");
|
||||
|
||||
// make a backup of the current profile and config files.
|
||||
CreateProfileBackupArchiveFile();
|
||||
CreateProfileBackupArchiveFile(_profile);
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
return;
|
||||
|
|
@ -1169,7 +1168,7 @@ namespace ServerManagerTool.Lib
|
|||
if (BackupWorldFile)
|
||||
{
|
||||
// make a backup of the current world file.
|
||||
CreateServerBackupArchiveFile(emailMessage);
|
||||
CreateServerBackupArchiveFile(emailMessage, _profile);
|
||||
|
||||
if (ExitCode != EXITCODE_NORMALEXIT)
|
||||
return;
|
||||
|
|
@ -1728,7 +1727,7 @@ namespace ServerManagerTool.Lib
|
|||
ExitCode = EXITCODE_NORMALEXIT;
|
||||
}
|
||||
|
||||
public void CreateProfileBackupArchiveFile(ServerProfileSnapshot profile = null)
|
||||
public void CreateProfileBackupArchiveFile(ServerProfileSnapshot profile)
|
||||
{
|
||||
// do nothing if profile is null
|
||||
if (profile == null)
|
||||
|
|
@ -1802,51 +1801,56 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
|
||||
// delete the old backup files
|
||||
try
|
||||
if (DeleteOldBackupFiles)
|
||||
{
|
||||
LogProfileMessage("Delete old profile backup files started...");
|
||||
|
||||
var backupFolder = GetProfileBackupFolder(_profile);
|
||||
var backupFileFilter = $"*{Config.Default.BackupExtension}";
|
||||
var backupDateFilter = DateTime.Now.AddDays(-BACKUP_DELETEINTERVAL);
|
||||
|
||||
var backupFiles = new DirectoryInfo(backupFolder).GetFiles(backupFileFilter).Where(f => f.LastWriteTime < backupDateFilter);
|
||||
foreach (var backupFile in backupFiles)
|
||||
try
|
||||
{
|
||||
try
|
||||
var deleteInterval = Config.Default.AutoBackup_EnableBackup ? Config.Default.AutoBackup_DeleteInterval : BACKUP_DELETEINTERVAL;
|
||||
|
||||
LogProfileMessage("Delete old profile backup files started...");
|
||||
|
||||
var backupFolder = GetProfileBackupFolder(_profile);
|
||||
var backupFileFilter = $"*{Config.Default.BackupExtension}";
|
||||
var backupDateFilter = DateTime.Now.AddDays(-deleteInterval);
|
||||
|
||||
var backupFiles = new DirectoryInfo(backupFolder).GetFiles(backupFileFilter).Where(f => f.LastWriteTime < backupDateFilter);
|
||||
foreach (var backupFile in backupFiles)
|
||||
{
|
||||
LogProfileMessage($"{backupFile.Name} was deleted, last updated {backupFile.CreationTime}.");
|
||||
backupFile.Delete();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
try
|
||||
{
|
||||
LogProfileMessage($"{backupFile.Name} was deleted, last updated {backupFile.CreationTime}.");
|
||||
backupFile.Delete();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogProfileError($"Error deleting old profile backup files.\r\n{ex.Message}", false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogProfileMessage("Delete old profile backup files finished.");
|
||||
}
|
||||
|
||||
// cleanup any backup folders from old backup process
|
||||
try
|
||||
{
|
||||
var backupFolder = GetProfileBackupFolder(_profile);
|
||||
|
||||
var oldBackupFolders = new DirectoryInfo(backupFolder).GetDirectories();
|
||||
foreach (var oldBackupFolder in oldBackupFolders)
|
||||
catch (Exception ex)
|
||||
{
|
||||
oldBackupFolder.Delete(true);
|
||||
LogProfileError($"Error deleting old profile backup files.\r\n{ex.Message}", false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogProfileMessage("Delete old profile backup files finished.");
|
||||
}
|
||||
|
||||
// cleanup any backup folders from old backup process
|
||||
try
|
||||
{
|
||||
var backupFolder = GetProfileBackupFolder(_profile);
|
||||
|
||||
var oldBackupFolders = new DirectoryInfo(backupFolder).GetDirectories();
|
||||
foreach (var oldBackupFolder in oldBackupFolders)
|
||||
{
|
||||
oldBackupFolder.Delete(true);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
|
@ -1855,7 +1859,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
}
|
||||
|
||||
public void CreateServerBackupArchiveFile(StringBuilder emailMessage, ServerProfileSnapshot profile = null)
|
||||
public void CreateServerBackupArchiveFile(StringBuilder emailMessage, ServerProfileSnapshot profile)
|
||||
{
|
||||
// do nothing if profile is null
|
||||
if (profile == null)
|
||||
|
|
@ -1958,7 +1962,7 @@ namespace ServerManagerTool.Lib
|
|||
}
|
||||
|
||||
// delete the old backup files
|
||||
if (DeleteOldServerBackupFiles)
|
||||
if (DeleteOldBackupFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -2939,7 +2943,7 @@ namespace ServerManagerTool.Lib
|
|||
Parallel.ForEach(_profiles.Keys.Where(p => p.EnableAutoBackup), profile => {
|
||||
var app = new ServerApp
|
||||
{
|
||||
DeleteOldServerBackupFiles = Config.Default.AutoBackup_DeleteOldFiles,
|
||||
DeleteOldBackupFiles = Config.Default.AutoBackup_DeleteOldFiles,
|
||||
OutputLogs = true,
|
||||
SendAlerts = true,
|
||||
SendEmails = true,
|
||||
|
|
|
|||
|
|
@ -1320,7 +1320,7 @@ namespace ServerManagerTool.Lib
|
|||
var app = new ServerApp(true)
|
||||
{
|
||||
BackupWorldFile = false,
|
||||
DeleteOldServerBackupFiles = false,
|
||||
DeleteOldBackupFiles = false,
|
||||
SendAlerts = false,
|
||||
SendEmails = false,
|
||||
OutputLogs = false
|
||||
|
|
|
|||
|
|
@ -340,7 +340,7 @@
|
|||
</TextBox.Text>
|
||||
</TextBox>
|
||||
|
||||
<CheckBox Grid.Row="0" Grid.Column="2" Margin="5,0,0,0" Content="{DynamicResource GlobalSettings_DeleteOldFilesLabel}" IsChecked="{Binding Config.AutoBackup_DeleteOldFiles, Mode=TwoWay}" ToolTip="{DynamicResource GlobalSettings_UseSmartCopyTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
|
||||
<CheckBox Grid.Row="0" Grid.Column="2" Margin="5,0,0,0" Content="{DynamicResource GlobalSettings_DeleteOldFilesLabel}" IsChecked="{Binding Config.AutoBackup_DeleteOldFiles, Mode=TwoWay}" ToolTip="{DynamicResource GlobalSettings_DeleteOldFilesTooltip}" VerticalAlignment="Center" HorizontalAlignment="Left"/>
|
||||
<cctl:AnnotatedSlider Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" Margin="5,0,5,0" Label="{DynamicResource GlobalSettings_DeleteIntervalLabel}" Value="{Binding Config.AutoBackup_DeleteInterval}" Minimum="1" Maximum="1000" SmallChange="1" LargeChange="2" TickFrequency="5" LabelRelativeWidth="Auto" SliderRelativeWidth="15*" SuffixRelativeWidth="Auto" Suffix="{DynamicResource SliderUnits_Days}" ToolTip="{DynamicResource GlobalSettings_DeleteIntervalTooltip}" IsEnabled="{Binding Config.AutoBackup_DeleteOldFiles}"/>
|
||||
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="{DynamicResource GlobalSettings_BackupWorldSaveLabel}" VerticalAlignment="Center"/>
|
||||
|
|
|
|||
|
|
@ -825,7 +825,7 @@ namespace ServerManagerTool
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
SendEmails = false,
|
||||
OutputLogs = false,
|
||||
ServerProcess = ServerProcessType.Backup,
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -396,7 +396,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -497,7 +497,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -598,7 +598,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -701,7 +701,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
@ -805,7 +805,7 @@ namespace ServerManagerTool.Utils
|
|||
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,29 @@
|
|||
<link href="http://servermanagers.freeforums.net/" />
|
||||
<updated>2021-12-17T00:00:00Z</updated>
|
||||
|
||||
<entry>
|
||||
<id>urn:uuid:40905243-2E97-4FCD-ACEA-53C9D42E69F0</id>
|
||||
<title>1.1.58 (1.1.58.12)</title>
|
||||
<summary>1.1.58.12</summary>
|
||||
<link href="" />
|
||||
<updated>2021-12-18T00:00:00Z</updated>
|
||||
<content type="xhtml">
|
||||
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
|
||||
<p>
|
||||
<u style="font-size: .9em;">BUGFIX</u>
|
||||
<br/>
|
||||
<ul>
|
||||
<li>Fixed the cleanup of the User config backup files.</li>
|
||||
</ul>
|
||||
</p>
|
||||
</div>
|
||||
</content>
|
||||
<author>
|
||||
<name>bletch</name>
|
||||
<email>bletch1971@hotmail.com</email>
|
||||
</author>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<id>urn:uuid:40905243-2E97-4FCD-ACEA-53C9D42E69F0</id>
|
||||
<title>1.1.58 (1.1.58.11)</title>
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ namespace ServerManagerTool.Windows
|
|||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldServerBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
SendEmails = false,
|
||||
OutputLogs = false,
|
||||
ServerProcess = ServerProcessType.Backup,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using Newtonsoft.Json;
|
||||
using ServerManagerTool.Common.Lib;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
|
|
@ -8,7 +10,7 @@ namespace ServerManagerTool.Common.Utils
|
|||
{
|
||||
public static class SettingsUtils
|
||||
{
|
||||
public static void BackupUserConfigSettings(System.Configuration.ApplicationSettingsBase settings, string fileName, string settingsPath, string backupPath)
|
||||
public static void BackupUserConfigSettings(ApplicationSettingsBase settings, string fileName, string settingsPath, string backupPath)
|
||||
{
|
||||
if (settings == null || string.IsNullOrWhiteSpace(fileName))
|
||||
return;
|
||||
|
|
@ -34,7 +36,7 @@ namespace ServerManagerTool.Common.Utils
|
|||
if (!string.IsNullOrWhiteSpace(backupPath))
|
||||
{
|
||||
// create a backup of the settings file
|
||||
var backupFile = IOUtils.NormalizePath(Path.Combine(backupPath, $"{settingsFileName}_{DateTime.UtcNow.ToString("yyyyMMdd_HHmmss")}{settingsFileExt}"));
|
||||
var backupFile = IOUtils.NormalizePath(Path.Combine(backupPath, $"{settingsFileName}_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}{settingsFileExt}"));
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -46,30 +48,45 @@ namespace ServerManagerTool.Common.Utils
|
|||
{
|
||||
// do nothing, just exit
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var filesToDelete = new DirectoryInfo(backupPath).GetFiles($"{settingsFileName}_*{settingsFileExt}").Where(f => f.LastWriteTimeUtc.AddDays(7) < DateTime.UtcNow);
|
||||
foreach (var fileToDelete in filesToDelete)
|
||||
{
|
||||
try
|
||||
{
|
||||
fileToDelete.Delete();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// do nothing, just exit
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// do nothing, just exit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MigrateSettings(System.Configuration.ApplicationSettingsBase settings, string settingsFile)
|
||||
public static void DeleteBackupUserConfigFiles(string fileName, string backupPath, int interval)
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.WriteLine("Deleting old config backup files started...");
|
||||
|
||||
var backupFileName = Path.GetFileNameWithoutExtension(fileName);
|
||||
var backupFileExt = Path.GetExtension(fileName);
|
||||
var backupFileFilter = $"{backupFileName}_*{backupFileExt}";
|
||||
var backupDateFilter = DateTime.Now.AddDays(-interval);
|
||||
|
||||
var filesToDelete = new DirectoryInfo(backupPath).GetFiles(backupFileFilter).Where(f => f.LastWriteTime < backupDateFilter);
|
||||
foreach (var fileToDelete in filesToDelete)
|
||||
{
|
||||
try
|
||||
{
|
||||
fileToDelete.Delete();
|
||||
Debug.WriteLine($"{fileToDelete.Name} was deleted, last updated {fileToDelete.CreationTime}.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if unable to delete, do not bother
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"Error deleting old server backup files.\r\n{ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Debug.WriteLine("Deleting old config backup files finished.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void MigrateSettings(ApplicationSettingsBase settings, string settingsFile)
|
||||
{
|
||||
if (settings == null || string.IsNullOrWhiteSpace(settingsFile) || !File.Exists(settingsFile))
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue