lestrrat has asked for the wisdom of the Perl Monks concerning the following question:

We recently got cracked (ugh), and had the hosting service provider clean install a new OS (RH 7.2). I was to bring back our perl tools. We had perl5.00503 on our previous system, so this was partly a good thing... Now I was able to use a newer version. And so I started out upgrading perl (RH7.2 comes with 5.6.0 ), installing modules etc... Only, we seem to have this problem with our database files.

We have many databases, created by using perl's DB_File. When the upgrade happened and I tried to access the database to check on the data, I kept getting an undef from the result of tie()

So I boiled the problem down to this:

use DB_File; my %db; my $dbref = tie( %db, "DB_File", $filename ) || die $!;

The above dies with a "File exists" error. For the life of me, I don't understand why on earth this doesn't work...

Because of the error message, I tried using different flags for the fourth argument, like O_RDONLY, but that didn't help. I also checked that I have read/write permission....

I'm out of ideas now... any pointers are appreciated

Replies are listed 'Best First'.
Re: (lestrrat) DB_File woes
by perrin (Chancellor) on Jan 16, 2002 at 23:45 UTC
    A newer Red Hat probably comes with a newer version of Berkeley DB (libdb.so, I think). There may be incompatibilities. You might need to open these files on a machine with an older Perl and Berkeley DB, dump them to an intermediary format (CSV or XML), and then load them on the new machine. You can check http://sleepycat.com/ for info on compatibility between versions, or ask Red Hat if you pay them for support.

      I think you were right on the spot. file command gave me this:

      /my/dbfile.db: Berkeley DB 1.85 (Hash, version 2, native byte-order)

      Then I proceeded to find a tool called db_dump185, which can dump contents of a BerkleyDB file prior to version 1.86 ( which is apparently when the db format changed )

      lestrrat wonders why they couldn't just print out an error message like "Invalid file format" or some such thing....

      So anyway... it looks like I need to db_dump/db_load and change all the files. That doesn't sound like a fun job, but I'm happy that I can at least read the damn things :-)

      Thanks for your tip!

        Useful lesson for next time.

        Keep backups in ASCII format. :-)