[CalendarServer-changes] [9788] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Sep 7 09:30:40 PDT 2012


Revision: 9788
          http://trac.macosforge.org/projects/calendarserver/changeset/9788
Author:   sagen at apple.com
Date:     2012-09-07 09:30:40 -0700 (Fri, 07 Sep 2012)
Log Message:
-----------
Update the backup/restore tool to just grab the entire ServerRoot (and DataRoot if it's not under ServerRoot)

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/backup_pg.py
    CalendarServer/trunk/contrib/migration/calendarmigrator.py
    CalendarServer/trunk/contrib/migration/test/test_migrator.py

Modified: CalendarServer/trunk/calendarserver/tools/backup_pg.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/backup_pg.py	2012-09-06 23:56:41 UTC (rev 9787)
+++ CalendarServer/trunk/calendarserver/tools/backup_pg.py	2012-09-07 16:30:40 UTC (rev 9788)
@@ -21,8 +21,6 @@
 import subprocess
 import sys
 import tarfile
-from tempfile import mkstemp
-from shutil import rmtree
 
 from twistedcaldav.config import config
 from calendarserver.tools.util import loadConfig
@@ -162,38 +160,31 @@
 
     serverRoot = config.ServerRoot
     dataRoot = config.DataRoot
-    docRoot = config.DocumentRoot
-    configRoot = config.ConfigRoot
+    dumpPath = os.path.join(serverRoot, DUMPFILENAME)
 
     if command == "backup":
 
-        fd, tmpPath = mkstemp(suffix=".dbdump")
-
         try:
-            dumpData(tmpPath, verbose=verbose)
+            dumpData(dumpPath, verbose=verbose)
 
             if verbose:
                 print "Creating %s" % (filename,)
             tar = tarfile.open(filename, "w:gz")
+
             if verbose:
-                print "Adding %s" % (dataRoot,)
-            tar.add(dataRoot, "Data")
-            if verbose:
-                print "Adding %s" % (docRoot,)
-            tar.add(docRoot, "Documents")
-            if verbose:
-                print "Adding %s" % (configRoot,)
-            tar.add(configRoot, "Config")
-            if verbose:
-                print "Adding %s" % (tmpPath,)
-            tar.add(tmpPath, DUMPFILENAME)
+                print "Adding %s" % (serverRoot,)
+            tar.add(serverRoot)
+
+            if not dataRoot.startswith(serverRoot):
+                # DataRoot is not contained within ServerRoot (i.e, it's on
+                # another volume)
+                if verbose:
+                    print "Adding %s" % (dataRoot,)
+                tar.add(dataRoot)
+
             tar.close()
 
             if verbose:
-                print "Removing %s" % (tmpPath,)
-            os.remove(tmpPath)
-
-            if verbose:
                 print "Done"
         except BackupError, e:
             error("Failed to dump database; error: %s" % (e,))
@@ -202,32 +193,16 @@
 
         try:
             tar = tarfile.open(filename, "r:gz")
-            os.chdir(serverRoot)
 
-            if os.path.exists(dataRoot):
-                if verbose:
-                    print "Removing old DataRoot: %s" % (dataRoot,)
-                rmtree(dataRoot)
-
-            if os.path.exists(docRoot):
-                if verbose:
-                    print "Removing old DocumentRoot: %s" % (docRoot,)
-                rmtree(docRoot)
-
-            if os.path.exists(configRoot):
-                if verbose:
-                    print "Removing old ConfigRoot: %s" % (configRoot,)
-                rmtree(configRoot)
-
             if verbose:
                 print "Extracting from backup file: %s" % (filename,)
-            tar.extractall()
+            tar.extractall(path="/")
 
-            loadData(DUMPFILENAME, verbose=verbose)
+            loadData(dumpPath, verbose=verbose)
 
             if verbose:
-                print "Cleaning up database dump file: %s" % (DUMPFILENAME,)
-            os.remove(DUMPFILENAME)
+                print "Cleaning up database dump file: %s" % (dumpPath,)
+            os.remove(dumpPath)
 
         except BackupError, e:
             error("Failed to dump database; error: %s" % (e,))

Modified: CalendarServer/trunk/contrib/migration/calendarmigrator.py
===================================================================
--- CalendarServer/trunk/contrib/migration/calendarmigrator.py	2012-09-06 23:56:41 UTC (rev 9787)
+++ CalendarServer/trunk/contrib/migration/calendarmigrator.py	2012-09-07 16:30:40 UTC (rev 9788)
@@ -375,7 +375,6 @@
     newCalDAVDPlist["EnableCalDAV"] = enableCalDAV
     newCalDAVDPlist["EnableCardDAV"] = enableCardDAV
 
-
     log("Writing %s" % (newConfigFile,))
     writePlist(newCalDAVDPlist, newConfigFile)
 
@@ -483,6 +482,9 @@
     # New DSN value for server-specific Postgres
     combined["DSN"] = "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::"
 
+    # ConfigRoot is now always "Config"
+    combined["ConfigRoot"] = "Config"
+
     return adminChanges
 
 

Modified: CalendarServer/trunk/contrib/migration/test/test_migrator.py
===================================================================
--- CalendarServer/trunk/contrib/migration/test/test_migrator.py	2012-09-06 23:56:41 UTC (rev 9787)
+++ CalendarServer/trunk/contrib/migration/test/test_migrator.py	2012-09-07 16:30:40 UTC (rev 9788)
@@ -89,6 +89,7 @@
         expected = {
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : True,
             "HTTPPort": 8008,
@@ -127,6 +128,7 @@
         expected = {
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
@@ -165,6 +167,7 @@
         expected = {
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : True,
             "HTTPPort": 8008,
@@ -203,6 +206,7 @@
         expected = {
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : True,
             "HTTPPort": 8008,
@@ -241,6 +245,7 @@
         expected = {
             "BindHTTPPorts": [1111, 2222, 4444, 5555, 7777, 8888],
             "BindSSLPorts": [3333, 6666, 9999, 11111],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : True,
             "HTTPPort": 8888,
@@ -276,6 +281,7 @@
         expected = {
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
@@ -306,6 +312,7 @@
         expected = {
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : True,
             "HTTPPort": 8008,
@@ -327,6 +334,7 @@
         expected = {
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
@@ -374,6 +382,7 @@
             },
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
@@ -413,6 +422,7 @@
             },
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
@@ -465,6 +475,7 @@
             },
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
@@ -506,6 +517,7 @@
             },
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
@@ -547,6 +559,7 @@
             },
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
@@ -582,6 +595,7 @@
             },
             "BindHTTPPorts": [8008, 8800],
             "BindSSLPorts": [8443, 8843],
+            "ConfigRoot" : "Config",
             "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
             "EnableSSL" : False,
             "HTTPPort": 8008,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120907/3f58b0dc/attachment-0001.html>


More information about the calendarserver-changes mailing list