diff options
author | Adam Frisby | 2008-04-17 11:42:06 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-17 11:42:06 +0000 |
commit | 05708771bb493ace1cf956acfa7a29610c8809e8 (patch) | |
tree | eec5c7e1a89272b61b9c573c6e789b5732c21063 /OpenSim/Region | |
parent | * Added appropriate license.txt in ThirdPartyLicenses/ for APR. (diff) | |
download | opensim-SC-05708771bb493ace1cf956acfa7a29610c8809e8.zip opensim-SC-05708771bb493ace1cf956acfa7a29610c8809e8.tar.gz opensim-SC-05708771bb493ace1cf956acfa7a29610c8809e8.tar.bz2 opensim-SC-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 '')
3 files changed, 178 insertions, 6 deletions
diff --git a/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs b/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs index 8613e77..16d7484 100644 --- a/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs +++ b/OpenSim/Region/Environment/Modules/ExportSerialiser/ExportSerialisationModule.cs | |||
@@ -12,19 +12,17 @@ using System.IO; | |||
12 | 12 | ||
13 | namespace OpenSim.Region.Environment.Modules.ExportSerialiser | 13 | namespace OpenSim.Region.Environment.Modules.ExportSerialiser |
14 | { | 14 | { |
15 | public class ExportSerialisationModule : IRegionModule | 15 | public class ExportSerialisationModule : IRegionModule, OpenSim.Region.Environment.Modules.ExportSerialiser.IRegionSerialiser |
16 | { | 16 | { |
17 | private List<Scene> m_regions = new List<Scene>(); | 17 | private List<Scene> m_regions = new List<Scene>(); |
18 | private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>(); | 18 | private List<IFileSerialiser> m_serialisers = new List<IFileSerialiser>(); |
19 | private Commander m_commander = new Commander("Export"); | 19 | private Commander m_commander = new Commander("Export"); |
20 | private string m_savedir = "exports" + "/"; | 20 | private string m_savedir = "exports" + "/"; |
21 | 21 | ||
22 | private List<string> SerialiseRegion(Scene scene) | 22 | public List<string> SerialiseRegion(Scene scene, string saveDir) |
23 | { | 23 | { |
24 | List<string> results = new List<string>(); | 24 | List<string> results = new List<string>(); |
25 | 25 | ||
26 | string saveDir = m_savedir + scene.RegionInfo.RegionID.ToString() + "/"; | ||
27 | |||
28 | if (!Directory.Exists(saveDir)) | 26 | if (!Directory.Exists(saveDir)) |
29 | { | 27 | { |
30 | Directory.CreateDirectory(saveDir); | 28 | Directory.CreateDirectory(saveDir); |
@@ -62,6 +60,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser | |||
62 | { | 60 | { |
63 | scene.RegisterModuleCommander("Export", m_commander); | 61 | scene.RegisterModuleCommander("Export", m_commander); |
64 | scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; | 62 | scene.EventManager.OnPluginConsole += EventManager_OnPluginConsole; |
63 | scene.RegisterModuleInterface<IRegionSerialiser>(this); | ||
65 | 64 | ||
66 | lock (m_regions) | 65 | lock (m_regions) |
67 | { | 66 | { |
@@ -88,7 +87,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser | |||
88 | { | 87 | { |
89 | if (region.RegionInfo.RegionName == (string)args[0]) | 88 | if (region.RegionInfo.RegionName == (string)args[0]) |
90 | { | 89 | { |
91 | List<string> results = SerialiseRegion(region); | 90 | List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/"); |
92 | } | 91 | } |
93 | } | 92 | } |
94 | } | 93 | } |
@@ -97,7 +96,7 @@ namespace OpenSim.Region.Environment.Modules.ExportSerialiser | |||
97 | { | 96 | { |
98 | foreach (Scene region in m_regions) | 97 | foreach (Scene region in m_regions) |
99 | { | 98 | { |
100 | List<string> results = SerialiseRegion(region); | 99 | List<string> results = SerialiseRegion(region, m_savedir + region.RegionInfo.RegionID.ToString() + "/"); |
101 | } | 100 | } |
102 | } | 101 | } |
103 | 102 | ||
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 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using 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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using Nini.Config; | ||
4 | using OpenSim.Region.Environment.Interfaces; | ||
5 | using OpenSim.Region.Environment.Scenes; | ||
6 | using OpenSim.Region.Environment.Modules.ExportSerialiser; | ||
7 | |||
8 | using PumaCode.SvnDotNet.SubversionSharp; | ||
9 | using PumaCode.SvnDotNet.AprSharp; | ||
10 | |||
11 | namespace 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 | } | ||