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> |
3245f058 |
7 | # Version: 1.03 |
8 | # Date 17th September 2000 |
a9fd575d |
9 | # |
d63909e4 |
10 | # Copyright (c) 1998-2002 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 | ( |
21 | 0x053162 => { |
039d031f |
22 | Type => "Btree", |
a9fd575d |
23 | Versions => |
24 | { |
25 | 1 => "Unknown (older than 1.71)", |
26 | 2 => "Unknown (older than 1.71)", |
27 | 3 => "1.71 -> 1.85, 1.86", |
28 | 4 => "Unknown", |
29 | 5 => "2.0.0 -> 2.3.0", |
039d031f |
30 | 6 => "2.3.1 -> 2.7.7", |
3245f058 |
31 | 7 => "3.0.x", |
efc79c7d |
32 | 8 => "3.1.x -> 4.0.x", |
33 | 9 => "4.1.x or greater", |
a9fd575d |
34 | } |
35 | }, |
36 | 0x061561 => { |
039d031f |
37 | Type => "Hash", |
a9fd575d |
38 | Versions => |
39 | { |
40 | 1 => "Unknown (older than 1.71)", |
41 | 2 => "1.71 -> 1.85", |
42 | 3 => "1.86", |
43 | 4 => "2.0.0 -> 2.1.0", |
039d031f |
44 | 5 => "2.2.6 -> 2.7.7", |
3245f058 |
45 | 6 => "3.0.x", |
efc79c7d |
46 | 7 => "3.1.x -> 4.0.x", |
47 | 8 => "4.1.x or greater", |
039d031f |
48 | } |
49 | }, |
50 | 0x042253 => { |
51 | Type => "Queue", |
52 | Versions => |
53 | { |
73969f8f |
54 | 1 => "3.0.x", |
55 | 2 => "3.1.x", |
efc79c7d |
56 | 3 => "3.2.x -> 4.0.x", |
57 | 4 => "4.1.x or greater", |
a9fd575d |
58 | } |
59 | }, |
60 | ) ; |
61 | |
62 | die "Usage: dbinfo file\n" unless @ARGV == 1 ; |
63 | |
64 | print "testing file $ARGV[0]...\n\n" ; |
65 | open (F, "<$ARGV[0]") or die "Cannot open file $ARGV[0]: $!\n" ; |
66 | |
67 | my $buff ; |
68 | read F, $buff, 20 ; |
69 | |
70 | my (@info) = unpack("NNNNN", $buff) ; |
71 | my (@info1) = unpack("VVVVV", $buff) ; |
72 | my ($magic, $version, $endian) ; |
73 | |
74 | if ($Data{$info[0]}) # first try DB 1.x format |
75 | { |
76 | $magic = $info[0] ; |
77 | $version = $info[1] ; |
78 | $endian = "Unknown" ; |
79 | } |
80 | elsif ($Data{$info[3]}) # next DB 2.x big endian |
81 | { |
82 | $magic = $info[3] ; |
83 | $version = $info[4] ; |
84 | $endian = "Big Endian" ; |
85 | } |
86 | elsif ($Data{$info1[3]}) # next DB 2.x little endian |
87 | { |
88 | $magic = $info1[3] ; |
89 | $version = $info1[4] ; |
90 | $endian = "Little Endian" ; |
91 | } |
92 | else |
93 | { die "not a Berkeley DB database file.\n" } |
94 | |
95 | my $type = $Data{$magic} ; |
73969f8f |
96 | $magic = sprintf "%06X", $magic ; |
a9fd575d |
97 | |
98 | my $ver_string = "Unknown" ; |
99 | $ver_string = $type->{Versions}{$version} |
100 | if defined $type->{Versions}{$version} ; |
101 | |
102 | print <<EOM ; |
103 | File Type: Berkeley DB $type->{Type} file. |
104 | File Version ID: $version |
105 | Built with Berkeley DB: $ver_string |
106 | Byte Order: $endian |
107 | Magic: $magic |
108 | EOM |
109 | |
110 | close F ; |
111 | |
112 | exit ; |