aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Modules/SvnSerialiser
diff options
context:
space:
mode:
authorAdam Frisby2008-04-17 11:42:06 +0000
committerAdam Frisby2008-04-17 11:42:06 +0000
commit05708771bb493ace1cf956acfa7a29610c8809e8 (patch)
treeeec5c7e1a89272b61b9c573c6e789b5732c21063 /OpenSim/Region/Modules/SvnSerialiser
parent* Added appropriate license.txt in ThirdPartyLicenses/ for APR. (diff)
downloadopensim-SC_OLD-05708771bb493ace1cf956acfa7a29610c8809e8.zip
opensim-SC_OLD-05708771bb493ace1cf956acfa7a29610c8809e8.tar.gz
opensim-SC_OLD-05708771bb493ace1cf956acfa7a29610c8809e8.tar.bz2
opensim-SC_OLD-05708771bb493ace1cf956acfa7a29610c8809e8.tar.xz
* Committing first version of SVN Backup Module
This is a module which allows you to periodically export a serialised version of your region to a SVN repository and store it there. It is still a work in progress and is currently disabled and incomplete, but some of the functionality is demonstratable. * Enjoy.
Diffstat (limited to 'OpenSim/Region/Modules/SvnSerialiser')
-rw-r--r--OpenSim/Region/Modules/SvnSerialiser/Properties/AssemblyInfo.cs36
-rw-r--r--OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs137
2 files changed, 173 insertions, 0 deletions
diff --git a/OpenSim/Region/Modules/SvnSerialiser/Properties/AssemblyInfo.cs b/OpenSim/Region/Modules/SvnSerialiser/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..3d0aa3e
--- /dev/null
+++ b/OpenSim/Region/Modules/SvnSerialiser/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("SvnSerialiser")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("")]
12[assembly: AssemblyProduct("SvnSerialiser")]
13[assembly: AssemblyCopyright("Copyright © 2008")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("c0893655-0c18-4dd7-8b5b-5f58ab1ec6c7")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32// You can specify all the values or you can default the Build and Revision Numbers
33// by using the '*' as shown below:
34// [assembly: AssemblyVersion("1.0.*")]
35[assembly: AssemblyVersion("1.0.0.0")]
36[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs b/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs
new file mode 100644
index 0000000..71882fd
--- /dev/null
+++ b/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs
@@ -0,0 +1,137 @@
1using System;
2using System.Collections.Generic;
3using Nini.Config;
4using OpenSim.Region.Environment.Interfaces;
5using OpenSim.Region.Environment.Scenes;
6using OpenSim.Region.Environment.Modules.ExportSerialiser;
7
8using PumaCode.SvnDotNet.SubversionSharp;
9using PumaCode.SvnDotNet.AprSharp;
10
11namespace OpenSim.Region.Modules.SvnSerialiser
12{
13 public class SvnBackupModule : IRegionModule
14 {
15 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
16
17 private SvnClient m_svnClient;
18 private bool m_installBackupOnLoad = false;
19 private string m_svnurl = "svn://url.tld/repository/";
20 private string m_svnuser = "user";
21 private string m_svnpass = "password";
22 private string m_svndir = "modsvn/";
23 private IRegionSerialiser m_serialiser;
24 private List<Scene> m_scenes = new List<Scene>();
25
26 #region SvnModule Core
27
28 public void SaveRegion(Scene scene)
29 {
30 List<string> filenames = m_serialiser.SerialiseRegion(scene, m_svndir);
31 foreach (string filename in filenames)
32 {
33 m_svnClient.Add3(filename, false, true, false);
34 }
35
36 m_svnClient.Commit3(filenames, true, false);
37 }
38
39 #endregion
40
41 #region SvnDotNet Callbacks
42
43 private SvnError SimpleAuth(out SvnAuthCredSimple svnCredentials, IntPtr baton,
44 AprString realm, AprString username, bool maySave, AprPool pool)
45 {
46 svnCredentials = SvnAuthCredSimple.Alloc(pool);
47 svnCredentials.Username = new AprString(m_svnuser, pool);
48 svnCredentials.Password = new AprString(m_svnpass, pool);
49 svnCredentials.MaySave = false;
50 return SvnError.NoError;
51 }
52
53 private SvnError GetCommitLogCallback(out AprString logMessage, out SvnPath tmpFile, AprArray commitItems, IntPtr baton, AprPool pool)
54 {
55 if (!commitItems.IsNull)
56 {
57 foreach (SvnClientCommitItem item in commitItems)
58 {
59 m_log.Debug("[SVNBACKUP]: Updated " + item.Path.ToString() + " (" + item.Kind.ToString() + ") " + item.Revision.ToString());
60 m_log.Debug("[SVNBACKUP]: " + item.Url.ToString() + " -> " + item.CopyFromUrl.ToString());
61 }
62 }
63
64 m_log.Debug("[SVNBACKUP]: Appending log message.");
65
66 logMessage = new AprString("Automated Region Backup", pool);
67 tmpFile = new SvnPath(pool);
68
69 return (SvnError.NoError);
70 }
71
72 #endregion
73
74 #region IRegionModule Members
75
76 public void Initialise(Scene scene, IConfigSource source)
77 {
78 lock (m_scenes)
79 {
80 m_scenes.Add(scene);
81 }
82
83 scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole;
84 }
85
86 void EventManager_OnPluginConsole(string[] args)
87 {
88 if (args[0] == "testsvn")
89 SaveRegion(m_scenes[0]);
90 }
91
92 public void PostInitialise()
93 {
94 m_log.Info("[SVNBACKUP]: Disabled.");
95 return;
96
97 m_log.Info("[SVNBACKUP]: Connecting...");
98
99 m_svnClient = new SvnClient();
100 m_svnClient.AddUsernameProvider();
101 m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2);
102 m_svnClient.OpenAuth();
103
104 m_log.Info("[SVNBACKUP]: Checking out base directory...");
105
106 if (!System.IO.Directory.Exists(m_svndir))
107 System.IO.Directory.CreateDirectory(m_svndir);
108
109 m_svnClient.Checkout2(m_svnurl, m_svndir, Svn.Revision.Head, Svn.Revision.Head, true, false);
110
111 if (m_scenes.Count > 0)
112 m_serialiser = m_scenes[0].RequestModuleInterface<IRegionSerialiser>();
113
114 if (m_installBackupOnLoad)
115 {
116
117 }
118 }
119
120 public void Close()
121 {
122
123 }
124
125 public string Name
126 {
127 get { return "SvnBackupModule"; }
128 }
129
130 public bool IsSharedModule
131 {
132 get { return true; }
133 }
134
135 #endregion
136 }
137}