import Globals import os from Acquisition import aq_base from cStringIO import StringIO from Globals import MessageDialog from ZODB.PersistentMapping import PersistentMapping def backup(self, REQUEST=None, download=1, filename='allzope.zexp'): """ saves backup file to var or allows download of backup file""" if download: f = StringIO() else: f = os.path.join(Globals.data_dir, filename) self.c = PersistentMapping() for k, v in self.objectItems(): self.c[k] = aq_base(v) get_transaction().commit() self.c._p_jar.exportFile(self.c._p_oid, f) del self.c if download: REQUEST.RESPONSE.setHeader('Content-type', 'application/data') REQUEST.RESPONSE.setHeader('Content-Disposition', 'inline;filename=%s' % filename) return f.getvalue() else: return MessageDialog( title="Zope backed up successfully", message="All items in root sucessfully\ exported to
%s." % f, action="manage_main") def restore(self, REQUEST=None, filename='allzope.zexp'): """ restores backup file from 'import' """ dirname, file=os.path.split(filename) if dirname: raise 'Bad Request', 'Invalid file name %s' % filename instance_home = INSTANCE_HOME software_home = os.path.join(SOFTWARE_HOME, '..%s..' % os.sep) software_home = os.path.normpath(software_home) for impath in (instance_home, software_home): filepath = os.path.join(impath, 'import', filename) if os.path.exists(filepath): break else: raise 'Bad Request', 'File does not exist: %s' % filename conn = self._p_jar ob = conn.importFile(filepath) for k, v in ob.items(): try: self._delObject(k) except AttributeError: pass self._setObject(k, v) return MessageDialog( title="Zope restored successfully", message="All items from %s sucessfully\ imported into
root." % filepath, action="manage_main")