http://qs321.pair.com?node_id=217918


in reply to Parse MSSQL .bak file

In the world of total illogic which is that of our client, the requirement that required the data from this massive 2.9 gig BAK file is no longer required. However, I had nearly solved the problem based on all your suggestions. I downloaded a copy of MSSQL 2K Trial and was in the process of dumping the database into a more negotiable format. I originally tried MSDE, but you're limited to databases smaller than 2 gig.

Getting back to Perl, though: Looking through the BAK file in a hex editor, I found it difficult to see many patterns. I concure that it would be very non-trivial to write a Perl parser for such files. However, it ought to be do-able. If anyone had the time and interest, I'm sure folks who like MySQL or PostgreSQL would be fans of a utility that would let them easily migrate an MSSQL database into something a little more open source.

gryphon
code('Perl') || die;

Replies are listed 'Best First'.
Re: Re: Parse MSSQL .bak file
by mpeppler (Vicar) on Dec 05, 2002 at 23:00 UTC
    Well - if the server is running it should be fairly straightforward to copy the data to flat files. I understand that MS in its infinite wisdom has deprecated the bcp utility, but I've used the following with Sybase:

    #!/usr/bin/perl -w use strict; use Sybase::Simple; my $dbh = new Sybase::Simple 'sa', 'pwd', 'server'; my $tables = $dbh->ArrayOfScalar(" select name from $db..sysobjects where type = 'U'"); foreach my $tab (@$tables) { system("bcp $db..$tab out $tab.bcp -c -Usa -Ppwd -Sserver"); }
    A similar script should be feasible with MS-SQL, either using MS's native tools, or using functionality from the FreeTDS project.

    Michael