Thierry Belgium : Zope backup trouble "Attempt to store an object from a foreign database connection"
Hello, In the previous versions of Zope (like : 2.4.2); I used two external methods to make entire backup and restore of all the Zope documents, see : the source script and procedure below. Now, I install Zope 2.7.2 and then add my two external methods as usual to restore all my applications from the previous version (2.4.2). It works very well but when I try to use the backup method I receive the following error : "Attempt to store an object from a foreign database connection" Is it a bug or some modified functionality of Zope ? Somebody could guide me ? Thierry Thierry.Goyvaerts@skynet.be Procedure to install and use the full backup/restore methods : Create a module, backup.py, with the contents of the source (given in the tied code file) within the Extensions directory of your e-Solution instance. Create two external methods, "restore" and "backup" in your root folder by pointing them at Extensions/backup.py -> restore and Extensions/backup.py -> backup. After creating the two external methods, protect each of them with a management-level permission. To back up your e-Solution, visit the "test" tab of the backup external method. A file named "e-Solution_backup.zexp" will be downloaded to your local machine via your browser. To restore your e-solution, place the "e-Solution_backup.zexp" file in the "import" directory of your e-Solution instance, and press the "test" tab of the restore external method. Be careful, this overwrites anything that exists with the same name. Note that the "zexp" file created by 'backup' may not successfully be imported using the standard import feature, it needs to be imported via the "restore" external method. Source file Extensions\backup.py : 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='e-Solution_backup.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="e-Solution backed up successfully", message="<EM>All items in root</EM> sucessfully\ exported to <pre>%s</pre>." % f, action="manage_main") def restore(self, REQUEST=None, filename='e-Solution_backup.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="e-Solution restored successfully", message="All items from <EM>%s</EM> sucessfully\ imported into <pre>root</pre>." % filepath, action="manage_main")
participants (1)
-
GOYVAERTS Thierry