3 # Name: dbinfo -- identify berkeley DB version used to create
6 # Author: Paul Marquess <Paul.Marquess@btinternet.com>
10 # Copyright (c) 1998-2008 Paul Marquess. All rights reserved.
11 # This program is free software; you can redistribute it and/or
12 # modify it under the same terms as Perl itself.
14 # Todo: Print more stats on a db file, e.g. no of records
15 # add log/txn/lock files
21 0x053162 => # DB_BTREEMAGIC
24 Versions => # DB_BTREEVERSION
26 1 => [0, "Unknown (older than 1.71)"],
27 2 => [0, "Unknown (older than 1.71)"],
28 3 => [0, "1.71 -> 1.85, 1.86"],
30 5 => [0, "2.0.0 -> 2.3.0"],
31 6 => [0, "2.3.1 -> 2.7.7"],
33 8 => [0, "3.1.x -> 4.0.x"],
34 9 => [1, "4.1.x or greater"],
37 0x061561 => # DB_HASHMAGIC
40 Versions => # DB_HASHVERSION
42 1 => [0, "Unknown (older than 1.71)"],
43 2 => [0, "1.71 -> 1.85"],
45 4 => [0, "2.0.0 -> 2.1.0"],
46 5 => [0, "2.2.6 -> 2.7.7"],
48 7 => [0, "3.1.x -> 4.0.x"],
49 8 => [1, "4.1.x or greater"],
50 9 => [1, "4.6.x or greater"],
53 0x042253 => # DB_QAMMAGIC
56 Versions => # DB_QAMVERSION
60 3 => [0, "3.2.x -> 4.0.x"],
61 4 => [1, "4.1.x or greater"],
66 die "Usage: dbinfo file\n" unless @ARGV == 1 ;
68 print "testing file $ARGV[0]...\n\n" ;
69 open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ;
75 my (@info) = unpack("NNNNNNC", $buff) ;
76 my (@info1) = unpack("VVVVVVC", $buff) ;
77 my ($magic, $version, $endian, $encrypt) ;
79 if ($Data{$info[0]}) # first try DB 1.x format, big endian
83 $endian = "Big Endian" ;
84 $encrypt = "Not Supported";
86 elsif ($Data{$info1[0]}) # first try DB 1.x format, little endian
89 $version = $info1[1] ;
90 $endian = "Little Endian" ;
91 $encrypt = "Not Supported";
93 elsif ($Data{$info[3]}) # next DB 2.x big endian
97 $endian = "Big Endian" ;
99 elsif ($Data{$info1[3]}) # next DB 2.x little endian
102 $version = $info1[4] ;
103 $endian = "Little Endian" ;
106 { die "not a Berkeley DB database file.\n" }
108 my $type = $Data{$magic} ;
109 $magic = sprintf "%06X", $magic ;
111 my $ver_string = "Unknown" ;
113 if ( defined $type->{Versions}{$version} )
115 $ver_string = $type->{Versions}{$version}[1];
116 if ($type->{Versions}{$version}[0] )
117 { $encrypt = $info[6] ? "Enabled" : "Disabled" }
119 { $encrypt = "Not Supported" }
123 File Type: Berkeley DB $type->{Type} file.
124 File Version ID: $version
125 Built with Berkeley DB: $ver_string