Posts Tagged ‘zope ZODB undo fire’

To undo a transaction in the ZODB which is not listed in the ZMI

Owen Curtis-Quick - September 24th, 2008

If one were to delete data and wanted to bring it back to prevent impending
catastrophe. Follow the method below to mount an older version of the database and copy changes to the current.

$ ./bin/zopectl debug # enter debug mode
>>> import ZODB.DB
>>> import ZODB.FileStorage
>>> from ZODB.TimeStamp import TimeStamp
>>> import cPickle
>>> date_tuple = (2008,9,23,14,10) # date when data was safe
>>> special_date = TimeStamp(*date_tuple) # make date into special format
>>> filename = ‘/home/zope/prod1/zeo/var/Data.fs’ # system path to Data.fs
>>> storage = ZODB.FileStorage.FileStorage(filename, read_only=1, stop=`special_date`)
>>> DB = ZODB.DB(storage) # mount database
>>> conn = DB.open() # open database
>>> root = conn.root()['Application']
>>> old_data = root.path.to.zope_object # old data
>>> new_data = app.path.to.zope_object # new data
>>> new_data.attribute_name = cPickle.loads(cPickle.dumps(old_data.attribute_name)) # copy old data into new
>>> ZODB.Transaction.get_transaction().commit()

This is for Zope 2.7, be aware the imports are in slightly different in 2.8+