aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs47
-rw-r--r--OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs7
2 files changed, 52 insertions, 2 deletions
diff --git a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs
index bbb77ad..28dc5f5 100644
--- a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs
+++ b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs
@@ -78,6 +78,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
78 /// These conditions are heuristics to try and avoid taking a backup when the sim is busy. 78 /// These conditions are heuristics to try and avoid taking a backup when the sim is busy.
79 /// AutoBackupSkipAssets 79 /// AutoBackupSkipAssets
80 /// 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 80 /// 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
81 /// AutoBackupKeepFilesForDays
82 /// 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
81 /// AutoBackupScript: String. Default: not specified (disabled). 83 /// AutoBackupScript: String. Default: not specified (disabled).
82 /// File path to an executable script or binary to run when an automatic backup is taken. 84 /// File path to an executable script or binary to run when an automatic backup is taken.
83 /// The file should really be (Windows) an .exe or .bat, or (Linux/Mac) a shell script or binary. 85 /// 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
429 state.SkipAssets = tmpSkipAssets; 431 state.SkipAssets = tmpSkipAssets;
430 } 432 }
431 433
434 // How long to keep backup files in days, 0 Disables this feature
435 int tmpKeepFilesForDays = ResolveInt("AutoBackupKeepFilesForDays",
436 this.m_defaultState.KeepFilesForDays, config, regionConfig);
437 if (state == null && tmpKeepFilesForDays != this.m_defaultState.KeepFilesForDays)
438 {
439 state = new AutoBackupModuleState();
440 }
441
442 if (state != null)
443 {
444 state.KeepFilesForDays = tmpKeepFilesForDays;
445 }
446
432 // Set file naming algorithm 447 // Set file naming algorithm
433 string stmpNamingType = ResolveString("AutoBackupNaming", 448 string stmpNamingType = ResolveString("AutoBackupNaming",
434 this.m_defaultState.NamingType.ToString(), config, regionConfig); 449 this.m_defaultState.NamingType.ToString(), config, regionConfig);
@@ -497,7 +512,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
497 catch (Exception e) 512 catch (Exception e)
498 { 513 {
499 m_log.Warn( 514 m_log.Warn(
500 "BAD NEWS. You won't be able to save backups to directory " + 515 "[AUTO BACKUP]: BAD NEWS. You won't be able to save backups to directory " +
501 state.BackupDir + 516 state.BackupDir +
502 " because it doesn't exist or there's a permissions issue with it. Here's the exception.", 517 " because it doesn't exist or there's a permissions issue with it. Here's the exception.",
503 e); 518 e);
@@ -614,7 +629,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
614 bool heuristicsPassed = false; 629 bool heuristicsPassed = false;
615 if (!this.m_timerMap.ContainsKey((Timer) sender)) 630 if (!this.m_timerMap.ContainsKey((Timer) sender))
616 { 631 {
617 m_log.Debug("Code-up error: timerMap doesn't contain timer " + sender); 632 m_log.Debug("[AUTO BACKUP]: Code-up error: timerMap doesn't contain timer " + sender);
618 } 633 }
619 634
620 List<IScene> tmap = this.m_timerMap[(Timer) sender]; 635 List<IScene> tmap = this.m_timerMap[(Timer) sender];
@@ -650,6 +665,9 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
650 } 665 }
651 this.DoRegionBackup(scene); 666 this.DoRegionBackup(scene);
652 } 667 }
668
669 // Remove Old Backups
670 this.RemoveOldFiles(state);
653 } 671 }
654 } 672 }
655 } 673 }
@@ -694,6 +712,31 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
694 iram.ArchiveRegion(savePath, guid, options); 712 iram.ArchiveRegion(savePath, guid, options);
695 } 713 }
696 714
715 // For the given state, remove backup files older than the states KeepFilesForDays property
716 private void RemoveOldFiles(AutoBackupModuleState state)
717 {
718 // 0 Means Disabled, Keep Files Indefinitely
719 if (state.KeepFilesForDays > 0)
720 {
721 string[] files = Directory.GetFiles(state.BackupDir, "*.oar");
722 DateTime CuttOffDate = DateTime.Now.AddDays(0 - state.KeepFilesForDays);
723
724 foreach (string file in files)
725 {
726 try
727 {
728 FileInfo fi = new FileInfo(file);
729 if (fi.CreationTime < CuttOffDate)
730 fi.Delete();
731 }
732 catch (Exception Ex)
733 {
734 m_log.Error("[AUTO BACKUP]: Error deleting old backup file '" + file + "': " + Ex.Message);
735 }
736 }
737 }
738 }
739
697 /// <summary> 740 /// <summary>
698 /// Called by the Event Manager when the OnOarFileSaved event is fired. 741 /// Called by the Event Manager when the OnOarFileSaved event is fired.
699 /// </summary> 742 /// </summary>
diff --git a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs
index ade25a5..ce7c368 100644
--- a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs
+++ b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs
@@ -49,6 +49,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
49 this.Timer = null; 49 this.Timer = null;
50 this.NamingType = NamingType.Time; 50 this.NamingType = NamingType.Time;
51 this.Script = null; 51 this.Script = null;
52 this.KeepFilesForDays = 0;
52 } 53 }
53 54
54 public Dictionary<Guid, string> LiveRequests 55 public Dictionary<Guid, string> LiveRequests
@@ -116,6 +117,12 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
116 set; 117 set;
117 } 118 }
118 119
120 public int KeepFilesForDays
121 {
122 get;
123 set;
124 }
125
119 public new string ToString() 126 public new string ToString()
120 { 127 {
121 string retval = ""; 128 string retval = "";