Backing up objects in db file

Skip Montanaro skip at pobox.com
Wed Mar 3 12:14:36 EST 2004


    Chris> I have a program that stores all its data as pickled objects
    Chris> inside a (berkeley) db file.

    Chris> Having been bitten a couple of times when the format changed
    Chris> across linux distribution upgrades, I'd like to write a simple
    Chris> program that dumps the objects to some kind of text format, which
    Chris> can then be reconstituted into objects later.  It can't just dump
    Chris> out the pickle format, because that could change between python
    Chris> versions.

Take a look at db2pickle.py and pickle2db.py in the Tools/scripts directory
of the source distribution.  I have no idea if they are included in the
Windows installer.  Here's the doc string from db2pickle.py:

  Synopsis: db2pickle.py [-h|-g|-b|-r|-a] dbfile [ picklefile ]

  Convert the database file given on the command line to a pickle
  representation.  The optional flags indicate the type of the database
  (hash, btree, recno).  The default is hash.  If a pickle file is named it
  is opened for write access (deleting any existing data).  If no pickle
  file is named, the pickle output is written to standard output.

Looking at that I can see I need to update the doc string.  The flags mean:

    -h - open as bsddb hash file
    -g - open as gdbm file
    -b - open as bsddb btree file
    -r - open as bsddb recno file
    -a - open using anydbm

Skip




More information about the Python-list mailing list