Commit | Line | Data |
a9fd575d |
1 | #!/usr/local/bin/perl |
2 | |
3 | # Name: dbinfo -- identify berkeley DB version used to create |
4 | # a database file |
5 | # |
6ca2e664 |
6 | # Author: Paul Marquess <Paul.Marquess@btinternet.com> |
083e9212 |
7 | # Version: 1.06 |
d8bf0b8c |
8 | # Date 27th March 2008 |
a9fd575d |
9 | # |
083e9212 |
10 | # Copyright (c) 1998-2008 Paul Marquess. All rights reserved. |
a9fd575d |
11 | # This program is free software; you can redistribute it and/or |
12 | # modify it under the same terms as Perl itself. |
13 | |
14 | # Todo: Print more stats on a db file, e.g. no of records |
15 | # add log/txn/lock files |
16 | |
17 | use strict ; |
18 | |
19 | my %Data = |
20 | ( |
083e9212 |
21 | 0x053162 => # DB_BTREEMAGIC |
22 | { |
039d031f |
23 | Type => "Btree", |
083e9212 |
24 | Versions => # DB_BTREEVERSION |
a9fd575d |
25 | { |
6d02d21f |
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"], |
29 | 4 => [0, "Unknown"], |
30 | 5 => [0, "2.0.0 -> 2.3.0"], |
31 | 6 => [0, "2.3.1 -> 2.7.7"], |
32 | 7 => [0, "3.0.x"], |
33 | 8 => [0, "3.1.x -> 4.0.x"], |
34 | 9 => [1, "4.1.x or greater"], |
a9fd575d |
35 | } |
36 | }, |
083e9212 |
37 | 0x061561 => # DB_HASHMAGIC |
38 | { |
039d031f |
39 | Type => "Hash", |
083e9212 |
40 | Versions => # DB_HASHVERSION |
a9fd575d |
41 | { |
6d02d21f |
42 | 1 => [0, "Unknown (older than 1.71)"], |
43 | 2 => [0, "1.71 -> 1.85"], |
44 | 3 => [0, "1.86"], |
45 | 4 => [0, "2.0.0 -> 2.1.0"], |
46 | 5 => [0, "2.2.6 -> 2.7.7"], |
47 | 6 => [0, "3.0.x"], |
48 | 7 => [0, "3.1.x -> 4.0.x"], |
49 | 8 => [1, "4.1.x or greater"], |
083e9212 |
50 | 9 => [1, "4.6.x or greater"], |
039d031f |
51 | } |
52 | }, |
083e9212 |
53 | 0x042253 => # DB_QAMMAGIC |
54 | { |
039d031f |
55 | Type => "Queue", |
083e9212 |
56 | Versions => # DB_QAMVERSION |
039d031f |
57 | { |
6d02d21f |
58 | 1 => [0, "3.0.x"], |
59 | 2 => [0, "3.1.x"], |
60 | 3 => [0, "3.2.x -> 4.0.x"], |
61 | 4 => [1, "4.1.x or greater"], |
a9fd575d |
62 | } |
63 | }, |
64 | ) ; |
65 | |
66 | die "Usage: dbinfo file\n" unless @ARGV == 1 ; |
67 | |
68 | print "testing file $ARGV[0]...\n\n" ; |
69 | open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ; |
70 | |
71 | my $buff ; |
6d02d21f |
72 | read F, $buff, 30 ; |
a9fd575d |
73 | |
a9fd575d |
74 | |
6d02d21f |
75 | my (@info) = unpack("NNNNNNC", $buff) ; |
76 | my (@info1) = unpack("VVVVVVC", $buff) ; |
77 | my ($magic, $version, $endian, $encrypt) ; |
78 | |
79 | if ($Data{$info[0]}) # first try DB 1.x format, big endian |
a9fd575d |
80 | { |
81 | $magic = $info[0] ; |
82 | $version = $info[1] ; |
6d02d21f |
83 | $endian = "Big Endian" ; |
84 | $encrypt = "Not Supported"; |
85 | } |
86 | elsif ($Data{$info1[0]}) # first try DB 1.x format, little endian |
87 | { |
88 | $magic = $info1[0] ; |
89 | $version = $info1[1] ; |
90 | $endian = "Little Endian" ; |
91 | $encrypt = "Not Supported"; |
a9fd575d |
92 | } |
93 | elsif ($Data{$info[3]}) # next DB 2.x big endian |
94 | { |
95 | $magic = $info[3] ; |
96 | $version = $info[4] ; |
97 | $endian = "Big Endian" ; |
98 | } |
99 | elsif ($Data{$info1[3]}) # next DB 2.x little endian |
100 | { |
101 | $magic = $info1[3] ; |
102 | $version = $info1[4] ; |
103 | $endian = "Little Endian" ; |
104 | } |
105 | else |
106 | { die "not a Berkeley DB database file.\n" } |
107 | |
108 | my $type = $Data{$magic} ; |
73969f8f |
109 | $magic = sprintf "%06X", $magic ; |
a9fd575d |
110 | |
111 | my $ver_string = "Unknown" ; |
6d02d21f |
112 | |
113 | if ( defined $type->{Versions}{$version} ) |
114 | { |
115 | $ver_string = $type->{Versions}{$version}[1]; |
116 | if ($type->{Versions}{$version}[0] ) |
117 | { $encrypt = $info[6] ? "Enabled" : "Disabled" } |
118 | else |
119 | { $encrypt = "Not Supported" } |
120 | } |
a9fd575d |
121 | |
122 | print <<EOM ; |
123 | File Type: Berkeley DB $type->{Type} file. |
124 | File Version ID: $version |
125 | Built with Berkeley DB: $ver_string |
126 | Byte Order: $endian |
127 | Magic: $magic |
6d02d21f |
128 | Encryption: $encrypt |
a9fd575d |
129 | EOM |
130 | |
131 | close F ; |
132 | |
133 | exit ; |