Backing up objects in db file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Stiles

    Backing up objects in db file


    Hi --

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

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

    There seem to be a few solutions in this space that nearly work - two
    incomplete YAML implementations , and a similiar maturity XML thing. Does
    anyone know of a solution that will both work, and is actively maintained ?

    --
    regards, chris
  • Skip Montanaro

    #2
    Re: Backing up objects in db file


    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

    Comment

    Working...