aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs74
1 files changed, 53 insertions, 21 deletions
diff --git a/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs b/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs
index c7e2fe0..f00470f 100644
--- a/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs
+++ b/OpenSim/Region/Modules/SvnSerialiser/SvnBackupModule.cs
@@ -19,8 +19,8 @@ namespace OpenSim.Region.Modules.SvnSerialiser
19 private SvnClient m_svnClient; 19 private SvnClient m_svnClient;
20 private bool m_enabled = false; 20 private bool m_enabled = false;
21 private bool m_installBackupOnLoad = false; 21 private bool m_installBackupOnLoad = false;
22 private string m_svnurl = "svn://your.svn.tld/"; 22 private string m_svnurl = "svn://insert.your.svn/here/";
23 private string m_svnuser = "user"; 23 private string m_svnuser = "username";
24 private string m_svnpass = "password"; 24 private string m_svnpass = "password";
25 private string m_svndir = "SVNmodule\\repo"; 25 private string m_svndir = "SVNmodule\\repo";
26 private IRegionSerialiser m_serialiser; 26 private IRegionSerialiser m_serialiser;
@@ -38,7 +38,6 @@ namespace OpenSim.Region.Modules.SvnSerialiser
38 { 38 {
39 m_svnClient.Add3(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString(), true, false, false); 39 m_svnClient.Add3(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString(), true, false, false);
40 } 40 }
41 // Ignore this error, it means the sim is already under version control.
42 catch (SvnException) { } 41 catch (SvnException) { }
43 42
44 List<string> svnfilenames = new List<string>(); 43 List<string> svnfilenames = new List<string>();
@@ -47,17 +46,21 @@ namespace OpenSim.Region.Modules.SvnSerialiser
47 svnfilenames.Add(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString()); 46 svnfilenames.Add(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString());
48 47
49 m_svnClient.Commit3(svnfilenames, true, false); 48 m_svnClient.Commit3(svnfilenames, true, false);
50 m_log.Info("[SVNBACKUP]: Backup successful."); 49 m_log.Info("[SVNBACKUP]: Region backup successful (" + scene.RegionInfo.RegionName + ").");
51 } 50 }
52 51
53 public void LoadRegion(Scene scene) 52 public void LoadRegion(Scene scene)
54 { 53 {
55 m_svnClient.Checkout2(m_svnurl, m_svndir, Svn.Revision.Head, Svn.Revision.Head, true, false);
56 scene.LoadPrimsFromXml2(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() + 54 scene.LoadPrimsFromXml2(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() +
57 Slash.DirectorySeparatorChar + "objects.xml"); 55 Slash.DirectorySeparatorChar + "objects.xml");
58 scene.RequestModuleInterface<OpenSim.Region.Environment.Modules.Terrain.ITerrainModule>().LoadFromFile(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() + 56 scene.RequestModuleInterface<OpenSim.Region.Environment.Modules.Terrain.ITerrainModule>().LoadFromFile(m_svndir + Slash.DirectorySeparatorChar + scene.RegionInfo.RegionID.ToString() +
59 Slash.DirectorySeparatorChar + "heightmap.r32"); 57 Slash.DirectorySeparatorChar + "heightmap.r32");
60 m_log.Info("[SVNBACKUP]: Load successful."); 58 m_log.Info("[SVNBACKUP]: Region load successful (" + scene.RegionInfo.RegionName + ").");
59 }
60
61 private void CheckoutSvn()
62 {
63 m_svnClient.Checkout2(m_svnurl, m_svndir, Svn.Revision.Head, Svn.Revision.Head, true, false);
61 } 64 }
62 65
63 #endregion 66 #endregion
@@ -110,6 +113,7 @@ namespace OpenSim.Region.Modules.SvnSerialiser
110 m_svnurl = source.Configs["SVN"].GetString("URL", m_svnurl); 113 m_svnurl = source.Configs["SVN"].GetString("URL", m_svnurl);
111 m_svnuser = source.Configs["SVN"].GetString("Username", m_svnuser); 114 m_svnuser = source.Configs["SVN"].GetString("Username", m_svnuser);
112 m_svnpass = source.Configs["SVN"].GetString("Password", m_svnpass); 115 m_svnpass = source.Configs["SVN"].GetString("Password", m_svnpass);
116 m_installBackupOnLoad = source.Configs["SVN"].GetString("ImportOnStartup", m_installBackupOnLoad);
113 } catch(Exception) { } 117 } catch(Exception) { }
114 118
115 lock (m_scenes) 119 lock (m_scenes)
@@ -123,9 +127,21 @@ namespace OpenSim.Region.Modules.SvnSerialiser
123 void EventManager_OnPluginConsole(string[] args) 127 void EventManager_OnPluginConsole(string[] args)
124 { 128 {
125 if (args[0] == "svn" && args[1] == "save") 129 if (args[0] == "svn" && args[1] == "save")
126 SaveRegion(m_scenes[0]); 130 {
131 foreach (Scene scene in m_scenes)
132 {
133 SaveRegion(scene);
134 }
135 }
127 if (args[0] == "svn" && args[1] == "load") 136 if (args[0] == "svn" && args[1] == "load")
128 LoadRegion(m_scenes[0]); 137 {
138 CheckoutSvn();
139
140 foreach (Scene scene in m_scenes)
141 {
142 LoadRegion(scene);
143 }
144 }
129 } 145 }
130 146
131 public void PostInitialise() 147 public void PostInitialise()
@@ -133,27 +149,43 @@ namespace OpenSim.Region.Modules.SvnSerialiser
133 if (m_enabled == false) 149 if (m_enabled == false)
134 return; 150 return;
135 151
136 m_log.Info("[SVNBACKUP]: Connecting..."); 152 m_log.Info("[SVNBACKUP]: Connecting to SVN server " + m_svnurl + " ...");
153 SetupSvnProvider();
137 154
155 m_log.Info("[SVNBACKUP]: Creating repository in " + m_svndir + ".");
156 CreateSvnDirectory();
157 CheckoutSvn();
158 SetupSerialiser();
159
160 if (m_installBackupOnLoad)
161 {
162 m_log.Info("[SVNBACKUP]: Importing latest SVN revision to scenes...");
163 foreach (Scene scene in m_scenes)
164 {
165 LoadRegion(scene);
166 }
167 }
168 }
169
170 private void SetupSerialiser()
171 {
172
173 if (m_scenes.Count > 0)
174 m_serialiser = m_scenes[0].RequestModuleInterface<IRegionSerialiser>();
175 }
176
177 private void SetupSvnProvider()
178 {
138 m_svnClient = new SvnClient(); 179 m_svnClient = new SvnClient();
139 m_svnClient.AddUsernameProvider(); 180 m_svnClient.AddUsernameProvider();
140 m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2); 181 m_svnClient.AddPromptProvider(new SvnAuthProviderObject.SimplePrompt(SimpleAuth), IntPtr.Zero, 2);
141 m_svnClient.OpenAuth(); 182 m_svnClient.OpenAuth();
183 }
142 184
143 m_log.Info("[SVNBACKUP]: Checking out base directory..."); 185 private void CreateSvnDirectory()
144 186 {
145 if (!System.IO.Directory.Exists(m_svndir)) 187 if (!System.IO.Directory.Exists(m_svndir))
146 System.IO.Directory.CreateDirectory(m_svndir); 188 System.IO.Directory.CreateDirectory(m_svndir);
147
148 m_svnClient.Checkout2(m_svnurl, m_svndir, Svn.Revision.Head, Svn.Revision.Head, true, false);
149
150 if (m_scenes.Count > 0)
151 m_serialiser = m_scenes[0].RequestModuleInterface<IRegionSerialiser>();
152
153 if (m_installBackupOnLoad)
154 {
155 //TODO
156 }
157 } 189 }
158 190
159 public void Close() 191 public void Close()