Include option to remove auto backup files older than given number of days. New property created to specify how many days to keep files for. Off by default, also made sure only oar files will be removed.

bullet-2.82
AliciaRaven 2014-06-28 07:42:24 +01:00 committed by Justin Clark-Casey (justincc)
parent 20b47fce07
commit 6e0e35cd66
2 changed files with 52 additions and 2 deletions

View File

@ -78,6 +78,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
/// These conditions are heuristics to try and avoid taking a backup when the sim is busy. /// These conditions are heuristics to try and avoid taking a backup when the sim is busy.
/// AutoBackupSkipAssets /// AutoBackupSkipAssets
/// If true, assets are not saved to the oar file. Considerably reduces impact on simulator when backing up. Intended for when assets db is backed up separately /// If true, assets are not saved to the oar file. Considerably reduces impact on simulator when backing up. Intended for when assets db is backed up separately
/// AutoBackupKeepFilesForDays
/// Backup files older than this value (in days) are deleted during the current backup process, 0 will disable this and keep all backup files indefinitely
/// AutoBackupScript: String. Default: not specified (disabled). /// AutoBackupScript: String. Default: not specified (disabled).
/// File path to an executable script or binary to run when an automatic backup is taken. /// File path to an executable script or binary to run when an automatic backup is taken.
/// The file should really be (Windows) an .exe or .bat, or (Linux/Mac) a shell script or binary. /// The file should really be (Windows) an .exe or .bat, or (Linux/Mac) a shell script or binary.
@ -429,6 +431,19 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
state.SkipAssets = tmpSkipAssets; state.SkipAssets = tmpSkipAssets;
} }
// How long to keep backup files in days, 0 Disables this feature
int tmpKeepFilesForDays = ResolveInt("AutoBackupKeepFilesForDays",
this.m_defaultState.KeepFilesForDays, config, regionConfig);
if (state == null && tmpKeepFilesForDays != this.m_defaultState.KeepFilesForDays)
{
state = new AutoBackupModuleState();
}
if (state != null)
{
state.KeepFilesForDays = tmpKeepFilesForDays;
}
// Set file naming algorithm // Set file naming algorithm
string stmpNamingType = ResolveString("AutoBackupNaming", string stmpNamingType = ResolveString("AutoBackupNaming",
this.m_defaultState.NamingType.ToString(), config, regionConfig); this.m_defaultState.NamingType.ToString(), config, regionConfig);
@ -497,7 +512,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
catch (Exception e) catch (Exception e)
{ {
m_log.Warn( m_log.Warn(
"BAD NEWS. You won't be able to save backups to directory " + "[AUTO BACKUP]: BAD NEWS. You won't be able to save backups to directory " +
state.BackupDir + state.BackupDir +
" because it doesn't exist or there's a permissions issue with it. Here's the exception.", " because it doesn't exist or there's a permissions issue with it. Here's the exception.",
e); e);
@ -614,7 +629,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
bool heuristicsPassed = false; bool heuristicsPassed = false;
if (!this.m_timerMap.ContainsKey((Timer) sender)) if (!this.m_timerMap.ContainsKey((Timer) sender))
{ {
m_log.Debug("Code-up error: timerMap doesn't contain timer " + sender); m_log.Debug("[AUTO BACKUP]: Code-up error: timerMap doesn't contain timer " + sender);
} }
List<IScene> tmap = this.m_timerMap[(Timer) sender]; List<IScene> tmap = this.m_timerMap[(Timer) sender];
@ -650,6 +665,9 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
} }
this.DoRegionBackup(scene); this.DoRegionBackup(scene);
} }
// Remove Old Backups
this.RemoveOldFiles(state);
} }
} }
} }
@ -694,6 +712,31 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
iram.ArchiveRegion(savePath, guid, options); iram.ArchiveRegion(savePath, guid, options);
} }
// For the given state, remove backup files older than the states KeepFilesForDays property
private void RemoveOldFiles(AutoBackupModuleState state)
{
// 0 Means Disabled, Keep Files Indefinitely
if (state.KeepFilesForDays > 0)
{
string[] files = Directory.GetFiles(state.BackupDir, "*.oar");
DateTime CuttOffDate = DateTime.Now.AddDays(0 - state.KeepFilesForDays);
foreach (string file in files)
{
try
{
FileInfo fi = new FileInfo(file);
if (fi.CreationTime < CuttOffDate)
fi.Delete();
}
catch (Exception Ex)
{
m_log.Error("[AUTO BACKUP]: Error deleting old backup file '" + file + "': " + Ex.Message);
}
}
}
}
/// <summary> /// <summary>
/// Called by the Event Manager when the OnOarFileSaved event is fired. /// Called by the Event Manager when the OnOarFileSaved event is fired.
/// </summary> /// </summary>

View File

@ -49,6 +49,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
this.Timer = null; this.Timer = null;
this.NamingType = NamingType.Time; this.NamingType = NamingType.Time;
this.Script = null; this.Script = null;
this.KeepFilesForDays = 0;
} }
public Dictionary<Guid, string> LiveRequests public Dictionary<Guid, string> LiveRequests
@ -116,6 +117,12 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
set; set;
} }
public int KeepFilesForDays
{
get;
set;
}
public new string ToString() public new string ToString()
{ {
string retval = ""; string retval = "";