[CalendarServer-changes] [766] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Dec 8 11:30:13 PST 2006
Revision: 766
http://trac.macosforge.org/projects/calendarserver/changeset/766
Author: dreid at apple.com
Date: 2006-12-08 11:30:13 -0800 (Fri, 08 Dec 2006)
Log Message:
-----------
simplified backup support
Modified Paths:
--------------
CalendarServer/trunk/bin/calendar_restore
CalendarServer/trunk/conf/85-calendar.plist
Modified: CalendarServer/trunk/bin/calendar_restore
===================================================================
--- CalendarServer/trunk/bin/calendar_restore 2006-12-08 18:03:57 UTC (rev 765)
+++ CalendarServer/trunk/bin/calendar_restore 2006-12-08 19:30:13 UTC (rev 766)
@@ -19,155 +19,74 @@
import os
import sys
-import shutil
import fnmatch
import plistlib
-import tempfile
-import commands
-from twistedcaldav.backup import *
+ServiceConf = "85-calendarServer.plist"
-SERVICE = "calendar"
+configFile = "/private/etc/caldavd/caldavd.plist"
-ServiceConf = "85-calendar.plist"
+documentRoot = "/Library/CalendarServer/Documents/"
-etcPath = "/private/etc/caldavd"
-configFile = "caldavd.plist"
-
removePatterns = ['.db.sqlite']
- at logFuncCall
-def restore_data(src, tmp, dst):
- debug('restoring data')
- docRoot = readConfig('/'.join((src,
- etcPath,
- configFile)))['DocumentRoot']
+class Options(dict):
+ def parseOpts(self, argv):
+ for x in xrange(0, len(argv)):
+ opt = argv[x]
+ if opt.startswith('-'):
+ self[opt.strip('-')] = argv[x+1]
- srcDoc = '/'.join((src, docRoot))
- tmpDoc = '/'.join((tmp, docRoot))
- dstDoc = '/'.join((dst, docRoot))
- mkroot(tmpDoc)
+def cleanDocRoot():
+ root = None
+ if os.path.exists(configFile):
+ root = plistlib.readPlist(configFile)['DocumentRoot']
+
+ if not root and os.path.exists(configFile + '.default'):
+ root = plistlib.readPlist(configFile + '.default')['DocumentRoot']
- copy(srcDoc, tmpDoc)
+ if not root:
+ root = documentRoot
- purge(tmpDoc, removePatterns)
+ if not root:
+ print "Could not find document root"
+ sys.exit(1)
- wasRunning = isRunning(SERVICE)
+ removed = []
- if wasRunning:
- serveradmin('stop', SERVICE)
+ for root, dirs, files in os.walk(root):
+ dirs.extend(files)
+ for file in dirs:
+ for pat in removePatterns:
+ if fnmatch.fnmatch(file, pat):
+ full = os.path.join(root, file)
- bakDoc = dstDoc.rstrip('/') + '.bak'
+ os.remove(full)
- move(dstDoc, bakDoc)
+ removed.append(full)
+
+ return removed
- try:
- move(tmpDoc, dstDoc)
- except OSError:
- move(bakDoc, dstDoc)
-
- else:
- remove(bakDoc)
-
- if wasRunning:
- serveradmin('start', SERVICE)
-
- debug('restoring data done')
-
-
- at logFuncCall
-def restore_configuration(src, tmp, dst):
- debug('restoring configuration')
-
- srcEtc = '/'.join((src, etcPath))
- tmpEtc = '/'.join((tmp, etcPath))
- dstEtc = '/'.join((dst, etcPath))
-
- mkroot(tmpEtc)
-
- copy(srcEtc, tmpEtc)
-
- debug('restoring configuration done')
-
-
- at logFuncCall
def cmd_restore(options):
- imgPath = options['imgPath']
- target = options['target']
- log = options['log']
- opt = options['opt']
+ cleanDocRoot()
- if opt not in ['all', 'data', 'configuration']:
- print "Unknown -opt value %s" % (opt,)
- sys.exit(1)
- sourceRoot = '/'.join(imgPath.split('/')[:-2])
- tmpRoot = tempfile.mktemp(prefix='calendar_restore-')
- dstRoot = target
-
- if opt in ['all', 'configuration']:
- restore_configuration(sourceRoot, tmpRoot, dstRoot)
-
- if opt in ['all', 'data']:
- restore_data(sourceRoot, tmpRoot, dstRoot)
-
-
- at logFuncCall
-def cmd_browse(options):
- pass
-
-
- at logFuncCall
-def cmd_actions(options):
- pl = plistlib.readPlist(os.path.join(SBSCONF, ServiceConf))
- for k,v in pl['RestoreActions'].iteritems():
- print "%s: %s" % (k,v)
-
-
- at logFuncCall
-def cmd_help(options):
- print "Usage:"
- print " -cmd actions :"
- print " Print out the supported actions from the config file"
- print " -cmd browse -imgPath path :"
- print " Show browse information for the given path"
- print " -cmd restore -imgPath path -opt option -target target"
- print (" Restore the files specified by option from the given path to "
- "the target")
- print " -cmd help : Display usage"
- print " -cmd version : Display version"
-
-
- at logFuncCall
-def cmd_version(options):
- pl = plistlib.readConfig(os.path.join(SBSCONF, ServiceConf))
- print pl['Version']
-
-
if __name__ == '__main__':
- debug("calendar_restore was called")
-
options = Options({'cmd': None,
'target': None,
- 'imgPath': None,
+ 'path': None,
'log': None,
'opt': 'all'})
options.parseOpts(sys.argv[1:])
-
- debug("parsing options: %s" % (options,))
cmd = globals().get('cmd_%s' % (options['cmd'],), None)
- debug("found command: %s" % (cmd,))
-
if not cmd:
print "Unknown Command: %s" % (options['cmd'],)
sys.exit(1)
cmd(options)
-
- debug("calendar_restore done")
Modified: CalendarServer/trunk/conf/85-calendar.plist
===================================================================
--- CalendarServer/trunk/conf/85-calendar.plist 2006-12-08 18:03:57 UTC (rev 765)
+++ CalendarServer/trunk/conf/85-calendar.plist 2006-12-08 19:30:13 UTC (rev 766)
@@ -3,38 +3,20 @@
<plist version="1.0">
<dict>
<key>ServiceName</key>
- <string>calendar</string>
+ <string>calendarServer</string>
<key>RestoreBinaryPath</key>
- <string>/usr/libexec/sbs_backup/calendar_restore</string>
- <key>RestoreLog</key>
- <string>/private/var/log/sbs_backup/calendar_restore.log</string>
- <key>RestoreActions</key>
- <dict>
- <key>Configuration</key>
- <string>configuration</string>
- <key>Data</key>
- <string>data</string>
- <key>Default</key>
- <string>all</string>
- <key>Browse</key>
- <string>browse</string>
- </dict>
+ <string>/usr/libexec/sbs_backup/calendar_restore</string>
+ <key>RestoreLog</key>
+ <string>/private/var/log/sbs_backup/calendar_restore.log</string>
+ <key>RestoreActions</key>
+ <dict>
+ <key>Default</key>
+ <string>all</string>
+ <key>Browse</key>
+ <string>browse</string>
+ </dict>
- <key>VerifyBinaryPath</key>
- <string>/usr/libexec/sbs_backup/sharePoints_verify</string>
- <key>VerifyLog</key>
- <string>/private/var/log/sbs_backup/sharePoints_verify.log</string>
- <key>VerifyActions</key>
- <dict>
- <key>Configuration</key>
- <string>configuration</string>
- <key>Data</key>
- <string>data</string>
- <key>Default</key>
- <string>all</string>
- </dict>
-
<key>Version</key>
<string>10.5</string>
</dict>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061208/6dd31969/attachment.html
More information about the calendarserver-changes
mailing list