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