diff options
Diffstat (limited to 'OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs')
-rw-r--r-- | OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs | 137 |
1 files changed, 137 insertions, 0 deletions
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 | } | ||