3 # Name: dbinfo -- identify berkeley DB version used to create
6 # Author: Paul Marquess <pmqs@cpan.org>
10 # Copyright (c) 1998-2020 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"],
64 0x074582 => # DB_HEAPMAGIC
67 Versions => # DB_HEAPVERSION
74 die "Usage: dbinfo file\n" unless @ARGV == 1 ;
76 print "testing file $ARGV[0]...\n\n" ;
77 open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ;
83 my (@info) = unpack("NNNNNNC", $buff) ;
84 my (@info1) = unpack("VVVVVVC", $buff) ;
85 my ($magic, $version, $endian, $encrypt) ;
87 if ($Data{$info[0]}) # first try DB 1.x format, big endian
91 $endian = "Big Endian" ;
92 $encrypt = "Not Supported";
94 elsif ($Data{$info1[0]}) # first try DB 1.x format, little endian
97 $version = $info1[1] ;
98 $endian = "Little Endian" ;
99 $encrypt = "Not Supported";
101 elsif ($Data{$info[3]}) # next DB 2.x big endian
104 $version = $info[4] ;
105 $endian = "Big Endian" ;
107 elsif ($Data{$info1[3]}) # next DB 2.x little endian
110 $version = $info1[4] ;
111 $endian = "Little Endian" ;
114 { die "not a Berkeley DB database file.\n" }
116 my $type = $Data{$magic} ;
117 $magic = sprintf "%06X", $magic ;
119 my $ver_string = "Unknown" ;
121 if ( defined $type->{Versions}{$version} )
123 $ver_string = $type->{Versions}{$version}[1];
124 if ($type->{Versions}{$version}[0] )
125 { $encrypt = $info[6] ? "Enabled" : "Disabled" }
127 { $encrypt = "Not Supported" }
131 File Type: Berkeley DB $type->{Type} file.
132 File Version ID: $version
133 Built with Berkeley DB: $ver_string