aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUbitUmarov2017-06-21 13:35:36 +0100
committerUbitUmarov2017-06-21 13:35:36 +0100
commit70da90273297dba5f1c4253f0ea8796575b26ed3 (patch)
treec94f3b204b7b4cea12279a9dfd1f22179f82bfe7
parent changes to AutoBackModule. Add option ALL to dooarbackup to save all regions... (diff)
downloadopensim-SC_OLD-70da90273297dba5f1c4253f0ea8796575b26ed3.zip
opensim-SC_OLD-70da90273297dba5f1c4253f0ea8796575b26ed3.tar.gz
opensim-SC_OLD-70da90273297dba5f1c4253f0ea8796575b26ed3.tar.bz2
opensim-SC_OLD-70da90273297dba5f1c4253f0ea8796575b26ed3.tar.xz
changes to AutoBackModule. Store folder and number of days expire is now also only defined in OpenSim.ini and so same for all regions.
-rw-r--r--OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs205
-rw-r--r--OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs17
2 files changed, 89 insertions, 133 deletions
diff --git a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs
index 05321cd..a14d819 100644
--- a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs
+++ b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModule.cs
@@ -66,7 +66,10 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
66 /// if false module is disable and all rest is ignored 66 /// if false module is disable and all rest is ignored
67 /// AutoBackupInterval: Double, non-negative value. Default: 720 (12 hours). 67 /// AutoBackupInterval: Double, non-negative value. Default: 720 (12 hours).
68 /// The number of minutes between each backup attempt. 68 /// The number of minutes between each backup attempt.
69 /// 69 /// AutoBackupDir: String. Default: "." (the current directory).
70 /// A directory (absolute or relative) where backups should be saved.
71 /// AutoBackupKeepFilesForDays remove files older than this number of days. 0 disables
72 ///
70 /// Next can be set on OpenSim.ini, as default, and or per region in Regions.ini 73 /// Next can be set on OpenSim.ini, as default, and or per region in Regions.ini
71 /// Region-specific settings take precedence. 74 /// Region-specific settings take precedence.
72 /// 75 ///
@@ -86,10 +89,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
86 /// AutoBackupNaming: string. Default: Time. 89 /// AutoBackupNaming: string. Default: Time.
87 /// One of three strings (case insensitive): 90 /// One of three strings (case insensitive):
88 /// "Time": Current timestamp is appended to file name. An existing file will never be overwritten. 91 /// "Time": Current timestamp is appended to file name. An existing file will never be overwritten.
89 /// "Sequential": A number is appended to the file name. So if RegionName_x.oar exists, we'll save to RegionName_{x+1}.oar next. An existing file will never be overwritten. 92 /// "Sequential": A number is appended to the file name. So if RegionName_x.oar exists, we'll save to RegionName_{x+1}.oar next. An existing file will never be overwritten.
90 /// "Overwrite": Always save to file named "${AutoBackupDir}/RegionName.oar", even if we have to overwrite an existing file. 93 /// "Overwrite": Always save to file named "${AutoBackupDir}/RegionName.oar", even if we have to overwrite an existing file.
91 /// AutoBackupDir: String. Default: "." (the current directory).
92 /// A directory (absolute or relative) where backups should be saved.
93 /// </remarks> 94 /// </remarks>
94 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AutoBackupModule")] 95 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AutoBackupModule")]
95 public class AutoBackupModule : ISharedRegionModule 96 public class AutoBackupModule : ISharedRegionModule
@@ -106,6 +107,10 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
106 private List<Scene> m_Scenes = new List<Scene> (); 107 private List<Scene> m_Scenes = new List<Scene> ();
107 private Timer m_masterTimer; 108 private Timer m_masterTimer;
108 private bool m_busy; 109 private bool m_busy;
110 private int m_KeepFilesForDays = -1;
111 private string m_backupDir;
112 private bool m_doneFirst;
113 private double m_baseInterval;
109 114
110 private IConfigSource m_configSource; 115 private IConfigSource m_configSource;
111 116
@@ -154,15 +159,19 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
154 if(!m_enabled) 159 if(!m_enabled)
155 return; 160 return;
156 161
157 m_log.Info("[AUTO BACKUP]: AutoBackupModule enabled"); 162 ParseDefaultConfig(moduleConfig);
158 m_masterTimer = new Timer(43200000); 163 if(!m_enabled)
159 m_masterTimer.Elapsed += HandleElapsed; 164 return;
160 m_masterTimer.AutoReset = false;
161 165
162 ParseDefaultConfig();
163 m_log.Debug("[AUTO BACKUP]: Default config:"); 166 m_log.Debug("[AUTO BACKUP]: Default config:");
164 m_log.Debug(m_defaultState.ToString()); 167 m_log.Debug(m_defaultState.ToString());
165 168
169 m_log.Info("[AUTO BACKUP]: AutoBackupModule enabled");
170 m_masterTimer = new Timer();
171 m_masterTimer.Interval = m_baseInterval;
172 m_masterTimer.Elapsed += HandleElapsed;
173 m_masterTimer.AutoReset = false;
174
166 m_console = MainConsole.Instance; 175 m_console = MainConsole.Instance;
167 176
168 m_console.Commands.AddCommand ( 177 m_console.Commands.AddCommand (
@@ -251,7 +260,6 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
251 /// </summary> 260 /// </summary>
252 void ISharedRegionModule.PostInitialise() 261 void ISharedRegionModule.PostInitialise()
253 { 262 {
254
255 } 263 }
256 264
257 #endregion 265 #endregion
@@ -261,18 +269,19 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
261 if (!m_enabled) 269 if (!m_enabled)
262 return; 270 return;
263 271
264 if(m_busy) 272 if (args.Length != 2)
265 { 273 {
266 MainConsole.Instance.OutputFormat ("Already doing a backup, please try later"); 274 MainConsole.Instance.OutputFormat ("Usage: dooarbackup <regionname>");
267 return; 275 return;
268 } 276 }
269 277
270 if (args.Length != 2) 278 if(m_busy)
271 { 279 {
272 MainConsole.Instance.OutputFormat ("Usage: dooarbackup <regionname>"); 280 MainConsole.Instance.OutputFormat ("Already doing a backup, please try later");
273 return; 281 return;
274 } 282 }
275 283
284 m_masterTimer.Stop();
276 m_busy = true; 285 m_busy = true;
277 286
278 bool found = false; 287 bool found = false;
@@ -289,13 +298,13 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
289 { 298 {
290 if(name == "ALL") 299 if(name == "ALL")
291 { 300 {
292 m_masterTimer.Stop();
293 for(int i = 0; i < scenes.Length; i++) 301 for(int i = 0; i < scenes.Length; i++)
294 { 302 {
295 s = scenes[i]; 303 s = scenes[i];
296 DoRegionBackup(s); 304 DoRegionBackup(s);
305 if (!m_enabled)
306 return;
297 } 307 }
298 m_busy = false;
299 return; 308 return;
300 } 309 }
301 310
@@ -305,37 +314,56 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
305 if (s.Name == name) 314 if (s.Name == name)
306 { 315 {
307 found = true; 316 found = true;
308 m_masterTimer.Stop();
309 DoRegionBackup(s); 317 DoRegionBackup(s);
310 break; 318 break;
311 } 319 }
312 } 320 }
313 } catch { } 321 }
314 322 catch { }
323 finally
324 {
325 if (m_enabled)
326 m_masterTimer.Start();
327 m_busy = false;
328 }
315 if (!found) 329 if (!found)
316 MainConsole.Instance.OutputFormat ("No such region {0}. Nothing to backup", name); 330 MainConsole.Instance.OutputFormat ("No such region {0}. Nothing to backup", name);
317 m_busy = false;
318 } 331 }
319 332
320 private void ParseDefaultConfig() 333 private void ParseDefaultConfig(IConfig config)
321 { 334 {
322 IConfig config = m_configSource.Configs["AutoBackupModule"]; 335
323 if (config == null) 336 m_backupDir = ".";
324 return; 337 string backupDir = config.GetString("AutoBackupDir", ".");
338 if (backupDir != ".")
339 {
340 try
341 {
342 DirectoryInfo dirinfo = new DirectoryInfo(backupDir);
343 if (!dirinfo.Exists)
344 dirinfo.Create();
345 }
346 catch (Exception e)
347 {
348 m_enabled = false;
349 m_log.WarnFormat("[AUTO BACKUP]: Error accessing backup folder {0}. Module disabled. {1}",
350 backupDir, e);
351 return;
352 }
353 }
354 m_backupDir = backupDir;
325 355
326 // Borrow an existing timer if one exists for the same interval; otherwise, make a new one.
327 double interval = config.GetDouble("AutoBackupInterval", 720); 356 double interval = config.GetDouble("AutoBackupInterval", 720);
328 interval *= 60000.0; 357 interval *= 60000.0;
329 m_masterTimer.Interval = interval; 358 m_baseInterval = interval;
359
360 // How long to keep backup files in days, 0 Disables this feature
361 m_KeepFilesForDays = config.GetInt("AutoBackupKeepFilesForDays",m_KeepFilesForDays);
330 362
331 m_defaultState.Enabled = config.GetBoolean("AutoBackup", m_defaultState.Enabled); 363 m_defaultState.Enabled = config.GetBoolean("AutoBackup", m_defaultState.Enabled);
332 364
333 // Included Option To Skip Assets
334 m_defaultState.SkipAssets = config.GetBoolean("AutoBackupSkipAssets",m_defaultState.SkipAssets); 365 m_defaultState.SkipAssets = config.GetBoolean("AutoBackupSkipAssets",m_defaultState.SkipAssets);
335 366
336 // How long to keep backup files in days, 0 Disables this feature
337 m_defaultState.KeepFilesForDays = config.GetInt("AutoBackupKeepFilesForDays",m_defaultState.KeepFilesForDays);
338
339 // Set file naming algorithm 367 // Set file naming algorithm
340 string stmpNamingType = config.GetString("AutoBackupNaming", m_defaultState.NamingType.ToString()); 368 string stmpNamingType = config.GetString("AutoBackupNaming", m_defaultState.NamingType.ToString());
341 NamingType tmpNamingType; 369 NamingType tmpNamingType;
@@ -354,25 +382,6 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
354 382
355 m_defaultState.Script = config.GetString("AutoBackupScript", m_defaultState.Script); 383 m_defaultState.Script = config.GetString("AutoBackupScript", m_defaultState.Script);
356 384
357 string backupDir = config.GetString("AutoBackupDir", ".");
358 if (backupDir != ".")
359 {
360 try
361 {
362 DirectoryInfo dirinfo = new DirectoryInfo(backupDir);
363 if (!dirinfo.Exists)
364 dirinfo.Create();
365 }
366 catch (Exception e)
367 {
368 m_log.Warn(
369 "[AUTO BACKUP]: BAD NEWS. You won't be able to save backups to directory " +
370 backupDir +
371 " because it doesn't exist or there's a permissions issue with it. Here's the exception.",
372 e);
373 }
374 }
375 m_defaultState.BackupDir = backupDir;
376 } 385 }
377 386
378 /// <summary> 387 /// <summary>
@@ -388,11 +397,9 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
388 return null; 397 return null;
389 398
390 string sRegionName; 399 string sRegionName;
391 string sRegionLabel;
392 AutoBackupModuleState state = null; 400 AutoBackupModuleState state = null;
393 401
394 sRegionName = scene.RegionInfo.RegionName; 402 sRegionName = scene.RegionInfo.RegionName;
395 sRegionLabel = sRegionName;
396 403
397 // Read the config settings and set variables. 404 // Read the config settings and set variables.
398 IConfig regionConfig = scene.Config.Configs[sRegionName]; 405 IConfig regionConfig = scene.Config.Configs[sRegionName];
@@ -406,9 +413,6 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
406 // Included Option To Skip Assets 413 // Included Option To Skip Assets
407 state.SkipAssets = regionConfig.GetBoolean("AutoBackupSkipAssets", m_defaultState.SkipAssets); 414 state.SkipAssets = regionConfig.GetBoolean("AutoBackupSkipAssets", m_defaultState.SkipAssets);
408 415
409 // How long to keep backup files in days, 0 Disables this feature
410 state.KeepFilesForDays = regionConfig.GetInt("AutoBackupKeepFilesForDays", m_defaultState.KeepFilesForDays);
411
412 // Set file naming algorithm 416 // Set file naming algorithm
413 string stmpNamingType = regionConfig.GetString("AutoBackupNaming", m_defaultState.NamingType.ToString()); 417 string stmpNamingType = regionConfig.GetString("AutoBackupNaming", m_defaultState.NamingType.ToString());
414 NamingType tmpNamingType; 418 NamingType tmpNamingType;
@@ -420,58 +424,16 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
420 tmpNamingType = NamingType.Overwrite; 424 tmpNamingType = NamingType.Overwrite;
421 else 425 else
422 { 426 {
423 m_log.Warn("Unknown naming type specified for region " + sRegionLabel + ": " + 427 m_log.Warn("Unknown naming type specified for region " + sRegionName + ": " +
424 stmpNamingType); 428 stmpNamingType);
425 tmpNamingType = NamingType.Time; 429 tmpNamingType = NamingType.Time;
426 } 430 }
427 m_defaultState.NamingType = tmpNamingType; 431 m_defaultState.NamingType = tmpNamingType;
428 432
429 state.Script = regionConfig.GetString("AutoBackupScript", m_defaultState.Script); 433 state.Script = regionConfig.GetString("AutoBackupScript", m_defaultState.Script);
430
431 string tmpBackupDir = regionConfig.GetString("AutoBackupDir", ".");
432 // Let's give the user some convenience and auto-mkdir
433 if (tmpBackupDir != "." && tmpBackupDir != m_defaultState.BackupDir)
434 {
435 try
436 {
437 DirectoryInfo dirinfo = new DirectoryInfo(state.BackupDir);
438 if (!dirinfo.Exists)
439 {
440 dirinfo.Create();
441 }
442 }
443 catch (Exception e)
444 {
445 m_log.Warn(
446 "[AUTO BACKUP]: BAD NEWS. You won't be able to save backups to directory " +
447 state.BackupDir +
448 " because it doesn't exist or there's a permissions issue with it:",
449 e);
450 }
451 }
452 state.BackupDir = tmpBackupDir;
453 return state; 434 return state;
454 } 435 }
455 436
456 /// <summary>
457 /// Helper function for ParseConfig.
458 /// </summary>
459 /// <param name="settingName"></param>
460 /// <param name="defaultValue"></param>
461 /// <param name="global"></param>
462 /// <param name="local"></param>
463 /// <returns></returns>
464 private bool ResolveBoolean(string settingName, bool defaultValue, IConfig global, IConfig local)
465 {
466 if(local != null)
467 {
468 return local.GetBoolean(settingName, global.GetBoolean(settingName, defaultValue));
469 }
470 else
471 {
472 return global.GetBoolean(settingName, defaultValue);
473 }
474 }
475 437
476 /// <summary> 438 /// <summary>
477 /// Called when any auto-backup timer expires. This starts the code path for actually performing a backup. 439 /// Called when any auto-backup timer expires. This starts the code path for actually performing a backup.
@@ -484,6 +446,9 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
484 return; 446 return;
485 447
486 m_busy = true; 448 m_busy = true;
449 if(m_doneFirst && m_KeepFilesForDays > 0)
450 RemoveOldFiles();
451
487 foreach (IScene scene in m_Scenes) 452 foreach (IScene scene in m_Scenes)
488 { 453 {
489 if (!m_enabled) 454 if (!m_enabled)
@@ -496,6 +461,8 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
496 m_masterTimer.Start(); 461 m_masterTimer.Start();
497 m_busy = false; 462 m_busy = false;
498 } 463 }
464
465 m_doneFirst = true;
499 } 466 }
500 467
501 /// <summary> 468 /// <summary>
@@ -526,7 +493,7 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
526 return; 493 return;
527 494
528 string savePath = BuildOarPath(scene.RegionInfo.RegionName, 495 string savePath = BuildOarPath(scene.RegionInfo.RegionName,
529 state.BackupDir, 496 m_backupDir,
530 state.NamingType); 497 state.NamingType);
531 if (savePath == null) 498 if (savePath == null)
532 { 499 {
@@ -548,26 +515,32 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
548 } 515 }
549 516
550 // For the given state, remove backup files older than the states KeepFilesForDays property 517 // For the given state, remove backup files older than the states KeepFilesForDays property
551 private void RemoveOldFiles(AutoBackupModuleState state) 518 private void RemoveOldFiles()
552 { 519 {
553 // 0 Means Disabled, Keep Files Indefinitely 520 string[] files;
554 if (state.KeepFilesForDays > 0) 521 try
555 { 522 {
556 string[] files = Directory.GetFiles(state.BackupDir, "*.oar"); 523 files = Directory.GetFiles(m_backupDir, "*.oar");
557 DateTime CuttOffDate = DateTime.Now.AddDays(0 - state.KeepFilesForDays); 524 }
525 catch (Exception Ex)
526 {
527 m_log.Error("[AUTO BACKUP]: Error reading backup folder " + m_backupDir + ": " + Ex.Message);
528 return;
529 }
558 530
559 foreach (string file in files) 531 DateTime CuttOffDate = DateTime.Now.AddDays(-m_KeepFilesForDays);
532
533 foreach (string file in files)
534 {
535 try
560 { 536 {
561 try 537 FileInfo fi = new FileInfo(file);
562 { 538 if (fi.CreationTime < CuttOffDate)
563 FileInfo fi = new FileInfo(file); 539 fi.Delete();
564 if (fi.CreationTime < CuttOffDate) 540 }
565 fi.Delete(); 541 catch (Exception Ex)
566 } 542 {
567 catch (Exception Ex) 543 m_log.Error("[AUTO BACKUP]: Error deleting old backup file '" + file + "': " + Ex.Message);
568 {
569 m_log.Error("[AUTO BACKUP]: Error deleting old backup file '" + file + "': " + Ex.Message);
570 }
571 } 544 }
572 } 545 }
573 } 546 }
diff --git a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs
index be5f2ae..fb87677 100644
--- a/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs
+++ b/OpenSim/Region/OptionalModules/World/AutoBackup/AutoBackupModuleState.cs
@@ -41,21 +41,17 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
41 public AutoBackupModuleState() 41 public AutoBackupModuleState()
42 { 42 {
43 Enabled = false; 43 Enabled = false;
44 BackupDir = ".";
45 SkipAssets = false; 44 SkipAssets = false;
46 NamingType = NamingType.Time; 45 NamingType = NamingType.Time;
47 Script = null; 46 Script = null;
48 KeepFilesForDays = 0;
49 } 47 }
50 48
51 public AutoBackupModuleState(AutoBackupModuleState copyFrom) 49 public AutoBackupModuleState(AutoBackupModuleState copyFrom)
52 { 50 {
53 Enabled = copyFrom.Enabled; 51 Enabled = copyFrom.Enabled;
54 BackupDir = copyFrom.BackupDir;
55 SkipAssets = copyFrom.SkipAssets; 52 SkipAssets = copyFrom.SkipAssets;
56 NamingType = copyFrom.NamingType; 53 NamingType = copyFrom.NamingType;
57 Script = copyFrom.Script; 54 Script = copyFrom.Script;
58 KeepFilesForDays = copyFrom.KeepFilesForDays;
59 } 55 }
60 56
61 public bool Enabled 57 public bool Enabled
@@ -76,30 +72,17 @@ namespace OpenSim.Region.OptionalModules.World.AutoBackup
76 set; 72 set;
77 } 73 }
78 74
79 public string BackupDir
80 {
81 get;
82 set;
83 }
84
85 public NamingType NamingType 75 public NamingType NamingType
86 { 76 {
87 get; 77 get;
88 set; 78 set;
89 } 79 }
90 80
91 public int KeepFilesForDays
92 {
93 get;
94 set;
95 }
96
97 public new string ToString() 81 public new string ToString()
98 { 82 {
99 string retval = ""; 83 string retval = "";
100 retval += "[AUTO BACKUP]: AutoBackup: " + (Enabled ? "ENABLED" : "DISABLED") + "\n"; 84 retval += "[AUTO BACKUP]: AutoBackup: " + (Enabled ? "ENABLED" : "DISABLED") + "\n";
101 retval += "[AUTO BACKUP]: Naming Type: " + NamingType.ToString() + "\n"; 85 retval += "[AUTO BACKUP]: Naming Type: " + NamingType.ToString() + "\n";
102 retval += "[AUTO BACKUP]: Backup Dir: " + BackupDir + "\n";
103 retval += "[AUTO BACKUP]: Script: " + Script + "\n"; 86 retval += "[AUTO BACKUP]: Script: " + Script + "\n";
104 return retval; 87 return retval;
105 } 88 }