"""Trac backup plugin for backup system. Hotcopy's are performed via the trac-admin command: trac-admin /path/to/env hotcopy /path/to/dest """ import plugins, os config = False location = '' nlocations = [] def init(cfg, *args, **kwargs): global location, nlocations, config config = cfg if len(args) != 1: if kwargs.has_key('location'): location = kwargs['location'] else: raise plugins.PluginError else: location = args[0] nlocations = plugins.normalize_path(args[0], cwd=False) def pre(): """Prepare a copy of the trac install using the hotcopy command.""" mkdir = "mkdir -p /tmp%s" cmd = "trac-admin %s hotcopy /tmp%s" if nlocations: for loc in nlocations: # trac's hotcopy requires the directory to not exist c = cmd % (loc, loc) m = mkdir % os.path.dirname(loc) print '>>>', m plugins.print_exec(m) print '>>>', c plugins.print_exec(c) else: c = cmd % (location, location) m = mkdir % os.path.dirname(location) print '>>>', m plugins.print_exec(m) print '>>>', c plugins.print_exec(c) def run(): """Backup all of the trac copies in /tmp. Read the rsync manpage in the 'relative' section to see why, but we want to run rsync with the source /tmp/./path/to/trac""" rsync = config.rsync() dest = config.destination() # we want rsync + source + dest def source(loc): return '/tmp/.%s ' % loc if nlocations: for loc in nlocations: c = rsync + source(loc) + dest print '>r>', c plugins.print_exec(c) else: c = rsync + source(location) + dest print '>r>', c plugins.print_exec(c) def post(): global config, location, nlocations cmd = "rm -rf /tmp%s" if nlocations: for loc in nlocations: print '<<<', cmd % loc plugins.print_exec(cmd % loc) else: print '<<<', cmd % location plugins.print_exec(cmd % location) config = False location = '' nlocations = []