diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/OptionalModules/World/AutoBackup | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/AutoBackup')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs | 123 | ||||
-rw-r--r-- | OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs | 14 |
2 files changed, 130 insertions, 7 deletions
diff --git a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs index 1d35c54..ceb3332 100644 --- a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs +++ b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs | |||
@@ -76,6 +76,10 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
76 | /// AutoBackupBusyCheck: True/False. Default: True. | 76 | /// AutoBackupBusyCheck: True/False. Default: True. |
77 | /// If True, we will only take an auto-backup if a set of conditions are met. | 77 | /// If True, we will only take an auto-backup if a set of conditions are met. |
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 | ||
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 | ||
79 | /// AutoBackupScript: String. Default: not specified (disabled). | 83 | /// AutoBackupScript: String. Default: not specified (disabled). |
80 | /// 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. |
81 | /// 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. |
@@ -111,6 +115,9 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
111 | 115 | ||
112 | private delegate T DefaultGetter<T>(string settingName, T defaultValue); | 116 | private delegate T DefaultGetter<T>(string settingName, T defaultValue); |
113 | private bool m_enabled; | 117 | private bool m_enabled; |
118 | private ICommandConsole m_console; | ||
119 | private List<Scene> m_Scenes = new List<Scene> (); | ||
120 | |||
114 | 121 | ||
115 | /// <summary> | 122 | /// <summary> |
116 | /// Whether the shared module should be enabled at all. NOT the same as m_Enabled in AutoBackupModuleState! | 123 | /// Whether the shared module should be enabled at all. NOT the same as m_Enabled in AutoBackupModuleState! |
@@ -202,8 +209,20 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
202 | /// Currently a no-op for AutoBackup because we have to wait for region to be fully loaded. | 209 | /// Currently a no-op for AutoBackup because we have to wait for region to be fully loaded. |
203 | /// </summary> | 210 | /// </summary> |
204 | /// <param name="scene"></param> | 211 | /// <param name="scene"></param> |
205 | void IRegionModuleBase.AddRegion(Scene scene) | 212 | void IRegionModuleBase.AddRegion (Scene scene) |
206 | { | 213 | { |
214 | if (!this.m_enabled) { | ||
215 | return; | ||
216 | } | ||
217 | lock (m_Scenes) { | ||
218 | m_Scenes.Add (scene); | ||
219 | } | ||
220 | m_console = MainConsole.Instance; | ||
221 | |||
222 | m_console.Commands.AddCommand ( | ||
223 | "AutoBackup", false, "dobackup", | ||
224 | "dobackup", | ||
225 | "do backup.", DoBackup); | ||
207 | } | 226 | } |
208 | 227 | ||
209 | /// <summary> | 228 | /// <summary> |
@@ -216,7 +235,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
216 | { | 235 | { |
217 | return; | 236 | return; |
218 | } | 237 | } |
219 | 238 | m_Scenes.Remove (scene); | |
220 | if (this.m_states.ContainsKey(scene)) | 239 | if (this.m_states.ContainsKey(scene)) |
221 | { | 240 | { |
222 | AutoBackupModuleState abms = this.m_states[scene]; | 241 | AutoBackupModuleState abms = this.m_states[scene]; |
@@ -258,6 +277,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
258 | AutoBackupModuleState abms = this.ParseConfig(scene, false); | 277 | AutoBackupModuleState abms = this.ParseConfig(scene, false); |
259 | m_log.Debug("[AUTO BACKUP]: Config for " + scene.RegionInfo.RegionName); | 278 | m_log.Debug("[AUTO BACKUP]: Config for " + scene.RegionInfo.RegionName); |
260 | m_log.Debug((abms == null ? "DEFAULT" : abms.ToString())); | 279 | m_log.Debug((abms == null ? "DEFAULT" : abms.ToString())); |
280 | |||
281 | m_states.Add(scene, abms); | ||
261 | } | 282 | } |
262 | 283 | ||
263 | /// <summary> | 284 | /// <summary> |
@@ -269,6 +290,28 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
269 | 290 | ||
270 | #endregion | 291 | #endregion |
271 | 292 | ||
293 | private void DoBackup (string module, string[] args) | ||
294 | { | ||
295 | if (args.Length != 2) { | ||
296 | MainConsole.Instance.OutputFormat ("Usage: dobackup <regionname>"); | ||
297 | return; | ||
298 | } | ||
299 | bool found = false; | ||
300 | string name = args [1]; | ||
301 | lock (m_Scenes) { | ||
302 | foreach (Scene s in m_Scenes) { | ||
303 | string test = s.Name.ToString (); | ||
304 | if (test == name) { | ||
305 | found = true; | ||
306 | DoRegionBackup (s); | ||
307 | } | ||
308 | } | ||
309 | if (!found) { | ||
310 | MainConsole.Instance.OutputFormat ("No such region {0}. Nothing to backup", name); | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | |||
272 | /// <summary> | 315 | /// <summary> |
273 | /// Set up internal state for a given scene. Fairly complex code. | 316 | /// Set up internal state for a given scene. Fairly complex code. |
274 | /// When this method returns, we've started auto-backup timers, put members in Dictionaries, and created a State object for this scene. | 317 | /// When this method returns, we've started auto-backup timers, put members in Dictionaries, and created a State object for this scene. |
@@ -334,7 +377,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
334 | double interval = | 377 | double interval = |
335 | this.ResolveDouble("AutoBackupInterval", this.m_defaultState.IntervalMinutes, | 378 | this.ResolveDouble("AutoBackupInterval", this.m_defaultState.IntervalMinutes, |
336 | config, regionConfig) * 60000.0; | 379 | config, regionConfig) * 60000.0; |
337 | if (state == null && interval != this.m_defaultState.IntervalMinutes*60000.0) | 380 | if (state == null && interval != this.m_defaultState.IntervalMinutes * 60000.0) |
338 | { | 381 | { |
339 | state = new AutoBackupModuleState(); | 382 | state = new AutoBackupModuleState(); |
340 | } | 383 | } |
@@ -412,6 +455,32 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
412 | state.BusyCheck = tmpBusyCheck; | 455 | state.BusyCheck = tmpBusyCheck; |
413 | } | 456 | } |
414 | 457 | ||
458 | // Included Option To Skip Assets | ||
459 | bool tmpSkipAssets = ResolveBoolean("AutoBackupSkipAssets", | ||
460 | this.m_defaultState.SkipAssets, config, regionConfig); | ||
461 | if (state == null && tmpSkipAssets != this.m_defaultState.SkipAssets) | ||
462 | { | ||
463 | state = new AutoBackupModuleState(); | ||
464 | } | ||
465 | |||
466 | if (state != null) | ||
467 | { | ||
468 | state.SkipAssets = tmpSkipAssets; | ||
469 | } | ||
470 | |||
471 | // How long to keep backup files in days, 0 Disables this feature | ||
472 | int tmpKeepFilesForDays = ResolveInt("AutoBackupKeepFilesForDays", | ||
473 | this.m_defaultState.KeepFilesForDays, config, regionConfig); | ||
474 | if (state == null && tmpKeepFilesForDays != this.m_defaultState.KeepFilesForDays) | ||
475 | { | ||
476 | state = new AutoBackupModuleState(); | ||
477 | } | ||
478 | |||
479 | if (state != null) | ||
480 | { | ||
481 | state.KeepFilesForDays = tmpKeepFilesForDays; | ||
482 | } | ||
483 | |||
415 | // Set file naming algorithm | 484 | // Set file naming algorithm |
416 | string stmpNamingType = ResolveString("AutoBackupNaming", | 485 | string stmpNamingType = ResolveString("AutoBackupNaming", |
417 | this.m_defaultState.NamingType.ToString(), config, regionConfig); | 486 | this.m_defaultState.NamingType.ToString(), config, regionConfig); |
@@ -480,7 +549,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
480 | catch (Exception e) | 549 | catch (Exception e) |
481 | { | 550 | { |
482 | m_log.Warn( | 551 | m_log.Warn( |
483 | "BAD NEWS. You won't be able to save backups to directory " + | 552 | "[AUTO BACKUP]: BAD NEWS. You won't be able to save backups to directory " + |
484 | state.BackupDir + | 553 | state.BackupDir + |
485 | " because it doesn't exist or there's a permissions issue with it. Here's the exception.", | 554 | " because it doesn't exist or there's a permissions issue with it. Here's the exception.", |
486 | e); | 555 | e); |
@@ -488,6 +557,9 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
488 | } | 557 | } |
489 | } | 558 | } |
490 | 559 | ||
560 | if(state == null) | ||
561 | return m_defaultState; | ||
562 | |||
491 | return state; | 563 | return state; |
492 | } | 564 | } |
493 | 565 | ||
@@ -594,7 +666,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
594 | bool heuristicsPassed = false; | 666 | bool heuristicsPassed = false; |
595 | if (!this.m_timerMap.ContainsKey((Timer) sender)) | 667 | if (!this.m_timerMap.ContainsKey((Timer) sender)) |
596 | { | 668 | { |
597 | m_log.Debug("Code-up error: timerMap doesn't contain timer " + sender); | 669 | m_log.Debug("[AUTO BACKUP]: Code-up error: timerMap doesn't contain timer " + sender); |
598 | } | 670 | } |
599 | 671 | ||
600 | List<IScene> tmap = this.m_timerMap[(Timer) sender]; | 672 | List<IScene> tmap = this.m_timerMap[(Timer) sender]; |
@@ -630,6 +702,9 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
630 | } | 702 | } |
631 | this.DoRegionBackup(scene); | 703 | this.DoRegionBackup(scene); |
632 | } | 704 | } |
705 | |||
706 | // Remove Old Backups | ||
707 | this.RemoveOldFiles(state); | ||
633 | } | 708 | } |
634 | } | 709 | } |
635 | } | 710 | } |
@@ -640,7 +715,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
640 | /// <param name="scene"></param> | 715 | /// <param name="scene"></param> |
641 | private void DoRegionBackup(IScene scene) | 716 | private void DoRegionBackup(IScene scene) |
642 | { | 717 | { |
643 | if (scene.RegionStatus != RegionStatus.Up) | 718 | if (!scene.Ready) |
644 | { | 719 | { |
645 | // We won't backup a region that isn't operating normally. | 720 | // We won't backup a region that isn't operating normally. |
646 | m_log.Warn("[AUTO BACKUP]: Not backing up region " + scene.RegionInfo.RegionName + | 721 | m_log.Warn("[AUTO BACKUP]: Not backing up region " + scene.RegionInfo.RegionName + |
@@ -662,7 +737,41 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
662 | m_pendingSaves.Add(guid, scene); | 737 | m_pendingSaves.Add(guid, scene); |
663 | state.LiveRequests.Add(guid, savePath); | 738 | state.LiveRequests.Add(guid, savePath); |
664 | ((Scene) scene).EventManager.OnOarFileSaved += new EventManager.OarFileSaved(EventManager_OnOarFileSaved); | 739 | ((Scene) scene).EventManager.OnOarFileSaved += new EventManager.OarFileSaved(EventManager_OnOarFileSaved); |
665 | iram.ArchiveRegion(savePath, guid, null); | 740 | |
741 | m_log.Info("[AUTO BACKUP]: Backing up region " + scene.RegionInfo.RegionName); | ||
742 | |||
743 | // Must pass options, even if dictionary is empty! | ||
744 | Dictionary<string, object> options = new Dictionary<string, object>(); | ||
745 | |||
746 | if (state.SkipAssets) | ||
747 | options["noassets"] = true; | ||
748 | |||
749 | iram.ArchiveRegion(savePath, guid, options); | ||
750 | } | ||
751 | |||
752 | // For the given state, remove backup files older than the states KeepFilesForDays property | ||
753 | private void RemoveOldFiles(AutoBackupModuleState state) | ||
754 | { | ||
755 | // 0 Means Disabled, Keep Files Indefinitely | ||
756 | if (state.KeepFilesForDays > 0) | ||
757 | { | ||
758 | string[] files = Directory.GetFiles(state.BackupDir, "*.oar"); | ||
759 | DateTime CuttOffDate = DateTime.Now.AddDays(0 - state.KeepFilesForDays); | ||
760 | |||
761 | foreach (string file in files) | ||
762 | { | ||
763 | try | ||
764 | { | ||
765 | FileInfo fi = new FileInfo(file); | ||
766 | if (fi.CreationTime < CuttOffDate) | ||
767 | fi.Delete(); | ||
768 | } | ||
769 | catch (Exception Ex) | ||
770 | { | ||
771 | m_log.Error("[AUTO BACKUP]: Error deleting old backup file '" + file + "': " + Ex.Message); | ||
772 | } | ||
773 | } | ||
774 | } | ||
666 | } | 775 | } |
667 | 776 | ||
668 | /// <summary> | 777 | /// <summary> |
diff --git a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs index f9e118b..ce7c368 100644 --- a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs +++ b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs | |||
@@ -45,9 +45,11 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
45 | this.Enabled = false; | 45 | this.Enabled = false; |
46 | this.BackupDir = "."; | 46 | this.BackupDir = "."; |
47 | this.BusyCheck = true; | 47 | this.BusyCheck = true; |
48 | this.SkipAssets = false; | ||
48 | this.Timer = null; | 49 | this.Timer = null; |
49 | this.NamingType = NamingType.Time; | 50 | this.NamingType = NamingType.Time; |
50 | this.Script = null; | 51 | this.Script = null; |
52 | this.KeepFilesForDays = 0; | ||
51 | } | 53 | } |
52 | 54 | ||
53 | public Dictionary<Guid, string> LiveRequests | 55 | public Dictionary<Guid, string> LiveRequests |
@@ -91,6 +93,12 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
91 | set; | 93 | set; |
92 | } | 94 | } |
93 | 95 | ||
96 | public bool SkipAssets | ||
97 | { | ||
98 | get; | ||
99 | set; | ||
100 | } | ||
101 | |||
94 | public string Script | 102 | public string Script |
95 | { | 103 | { |
96 | get; | 104 | get; |
@@ -109,6 +117,12 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup | |||
109 | set; | 117 | set; |
110 | } | 118 | } |
111 | 119 | ||
120 | public int KeepFilesForDays | ||
121 | { | ||
122 | get; | ||
123 | set; | ||
124 | } | ||
125 | |||
112 | public new string ToString() | 126 | public new string ToString() |
113 | { | 127 | { |
114 | string retval = ""; | 128 | string retval = ""; |