Path of lost file – ZODB Blobstorage

I had a task the other day of finding out the disk path of a broken blob file. I am using Zope2.12.23 with ZODB 3.9.7, python 2.6.

Blobstorage is a feature of Zope’s ZODB that allows you to store binary files on the disk, while managing them transparently as ZODB persistent objects. Them problem with them is that sometimes they get lost altogether with packing and removing transaction of their deletion from database, and a client or a CMS manager remembers he needed them restored. While creating incremental backups of Data.s with repozo is whatsoever in handy, backing up blobs can be disk consuming.

If you lost your file, but you have a Data.fs backup, and you need to know the disk path of the blob (so you can recover it from system backup), here’s how you do it:

First we’ll need to find out the directory. It depends on the oid of blob persistent object in ZODB and the selected layout of the blobstorage, be it bushy or lawn.

>>> bin/zope-instance debug
>>> layout_name = any_blobobj._p_jar._storage.fshelper.layout_name
>>> from ZODB.blob import FilesystemHelper
>>> fs = FilesystemHelper('/your/blobstorage/path/', layout_name)
>>> fs.getPathForOID(your_lost_blobobj._p_oid) # get the dir path where the file was saved

The file name is generated by the OID and the transaction ID (tid or serial) of the last commit on object.

>>> p, serial = your_lost_blobobj._p_jar._storage.load(lost_blobobj._p_oid, '')
>>> fs.getBlobFilename(lost_blobobj._p_oid, serial)

And there you have it, your file was saved at /your/blobstorage/path/0x00/0x00/0x00/0x00/0x00/0x01/0x07/0xbf/0x0396403e8323adcc.blob