[SVN] r610 - /branches/cyrus-db-type-check
debian at incase.de
debian at incase.de
Thu Sep 14 18:23:06 UTC 2006
Author: sven
Date: Thu Sep 14 20:23:05 2006
New Revision: 610
URL: https://mail.incase.de/viewcvs?rev=610&root=cyrus22&view=rev
Log:
Updated db-type-check script, still needs testing
Modified:
branches/cyrus-db-type-check
Modified: branches/cyrus-db-type-check
URL: https://mail.incase.de/viewcvs/branches/cyrus-db-type-check?rev=610&root=cyrus22&r1=609&r2=610&view=diff
==============================================================================
--- branches/cyrus-db-type-check (original)
+++ branches/cyrus-db-type-check Thu Sep 14 20:23:05 2006
@@ -1,7 +1,22 @@
-#!/usr/bin/perl
-my $hard_db_config="/usr/lib/cyrus/cyrus-db-types.txt";
-my $old_db_config="/usr/lib/cyrus/cyrus-db-types.active";
+#!/usr/bin/perl -w -T
+# cyrus-db-type-check copyright 2006 by Sven Mueller
+# This script is licensed under the terms of the
+# GNU General Public License version 2
+#
+
+# values to use for production
+#my $hard_db_config="/usr/lib/cyrus/cyrus-db-types.txt";
+#my $old_db_config="/usr/lib/cyrus/cyrus-db-types.active";
+#my $imapd_conf="/etc/imapd.conf";
+#my $debug=0;
+#my $verbose=0;
+# values to use for testing
+my $hard_db_config="/tmp/cyrus-db-types.txt";
+my $old_db_config="/tmp/cyrus-db-types.active";
my $imapd_conf="/tmp/imapd.conf";
+my $debug=0;
+my $verbose=0;
+
my %old_config;
my %running_config;
my %used_types;
@@ -19,7 +34,7 @@
my $val=$_;
$val =~ s/.* //;
$old_config{$key}=$val;
- printf("Read value for %s as %s\n",$key,$old_config{$key});
+ $debug && printf("Read value for %s as %s\n",$key,$old_config{$key});
}
close(OLDCONFIG);
#
@@ -34,7 +49,7 @@
my $val=$_;
$val =~ s/.* //;
$running_config{$key}=$val;
- printf("Read value for %s as %s\n",$key,$running_config{$key});
+ $debug && printf("Read value for %s as %s\n",$key,$running_config{$key});
}
close(HARDCONFIG);
#
@@ -52,47 +67,48 @@
$key =~ s/:.*//;
my $val=$line;
$val =~ s/.*:[[:space:]]*//;
- # printf("found: $key $val\n");
if ( $key eq "annotation_db" ) {
#imapd.conf: annotation_db: skiplist
#c-d-t.txt: ANNOTATION skiplist
$running_config{"ANNOTATION"}=$val;
- printf("Found ANNOTATION override: %s\n",$val);
+ $debug && printf("Found ANNOTATION override: %s\n",$val);
} elsif ( $key eq "duplicate_db" ) {
#imapd.conf: duplicate_db: berkeley-nosync
#c-d-t.txt: DUPLICATE berkeley-nosync
$running_config{"DUPLICATE"}=$val;
- printf("Found DUPLICATE override: %s\n",$val);
+ $debug && printf("Found DUPLICATE override: %s\n",$val);
} elsif ( $key eq "mboxlist_db" ) {
#imapd.conf: mboxlist_db: skiplist
#c-d-t.txt: MBOX skiplist
$running_config{"MBOX"}=$val;
- printf("Found MBOX override: %s\n",$val);
+ $debug && printf("Found MBOX override: %s\n",$val);
} elsif ( $key eq "ptscache_db" ) {
#imapd.conf: ptscache_db: berkeley
#c-d-t.txt: PTS berkeley
$running_config{"PTS"}=$val;
- printf("Found PTS override: %s\n",$val);
+ $debug && printf("Found PTS override: %s\n",$val);
} elsif ( $key eq "quota_db" ) {
#imapd.conf: quota_db: quotalegacy
#c-d-t.txt: QUOTA quotalegacy
$running_config{"QUOTA"}=$val;
- printf("Found QUOTA override: %s\n",$val);
+ $debug && printf("Found QUOTA override: %s\n",$val);
} elsif ( $key eq "seenstate_db" ) {
#imapd.conf: seenstate_db: skiplist
#c-d-t.txt: SEEN skiplist
$running_config{"SEEN"}=$val;
- printf("Found SEEN override: %s\n",$val);
+ $debug && printf("Found SEEN override: %s\n",$val);
} elsif ( $key eq "subscription_db" ) {
#imapd.conf: subscription_db: flat
#c-d-t.txt: SUBS flat
$running_config{"SUBS"}=$val;
- printf("Found SUBS override: %s\n",$val);
+ $debug && printf("Found SUBS override: %s\n",$val);
} elsif ( $key eq "tlscache_db" ) {
#imapd.conf: tlscache_db: berkeley-nosync
#c-d-t.txt: TLS berkeley-nosync
$running_config{"TLS"}=$val;
- printf("Found TLS override: %s\n",$val);
+ $debug && printf("Found TLS override: %s\n",$val);
+ } else {
+ $debug && printf("Discarding non-db setting: $key $val\n");
}
}
}
@@ -110,28 +126,92 @@
}
}
foreach my $i (keys(%used_types)) {
- printf("Database type %s used in: %s\n",$i,$used_types{$i});
+ ($debug) && printf("Database type %s used in: %s\n",$i,$used_types{$i});
+ }
+}
+
+sub runcheck {
+ my $bdb_used=0;
+ ($verbose) && printf("Checking wether any Berkeley DB is used\n");
+ foreach my $i ("berkeley","berkeley-nosync") {
+ if (defined($used_types{$i}) && $used_types{$i} ne "") {
+ ($verbose) && printf("Found %s to be used by: %s\n",$i,$used_types{$i});
+ $bdb_used=1;
+ }
+ }
+ if ($bdb_used == 0) { return 0; };
+ if (!defined($old_config{"DBENGINE"})) {
+ printf(STDERR "ERROR: Couldn't determine BDB type for current installation\n");
+ printf(STDERR " Proposed resolution: Check DB types manually\n");
+ printf(STDERR " This can be achieved by trying db*_verify on one\n");
+ printf(STDERR " of the BDB style databases (");
+ my $bdb_databases = "";
+ if ( defined($used_types{"berkeley"}) && defined($used_types{"berkeley_nosync"}) ) {
+ $bdb_databases=$used_types{"berkeley"}.",".$used_types{"berkeley_nosync"};
+ } elsif (defined($used_types{"berkeley"})) {
+ $bdb_databases=$used_types{"berkeley"};
+ } else { # berkeley_nosync must be in use
+ $bdb_databases=$used_types{"berkeley_nosync"};
+ }
+ printf(STDERR $bdb_databases . ").\n");
+ printf(STDERR " Start with the lowest version of db*_verify you have. If\n");
+ printf(STDERR " the database is from a higher BDB version, it will complain.\n");
+ return 1;
+ }
+ if (!defined($running_config{"DBENGINE"})) {
+ printf(STDERR "ERROR: Couldn't determine BDB type for current installation\n");
+ printf(STDERR "This indicates an error in the cyrus package you installed.\n");
+ printf(STDERR "Please revert to the version you had installed before.\n");
+ return 1;
+ }
+ if ($running_config{"DBENGINE"} eq $old_config{"DBENGINE"}) {
+ $verbose && printf("Everything should be fine, Berkeley DB versions match\n");
+ return 0;
}
}
sub usage {
- printf("Usage: cyrus-db-type-check {check|dump}\n");
+ printf("Usage: cyrus-db-type-check [-v] [-d] {check|dump}\n");
printf(" check checks wether last running config and current config\n");
printf(" are compatible\n");
+ printf(" verify checks wether current config matches actual format of\n");
+ printf(" the database files on disk\n");
printf(" dump dumps the current config in a format suitable for\n");
printf(" /usr/lib/cyrus/cyrus-db-types.active\n");
exit 1;
}
-
-if ( $#ARGV != 0 ) {
- usage;
-} elsif ($ARGV[0] eq "check") {
+my $docheck=0;
+my $dodump=0;
+while ($#ARGV >= 0) {
+ if ( $ARGV[0] eq "check" ) {
+ $docheck=1;
+ if ( $dodump ) {
+ printf(STDERR "dump and check can't be specified at the same time\n\n");
+ usage;
+ }
+ } elsif ( $ARGV[0] eq "dump" ) {
+ $dodump=1;
+ if ( $docheck ) {
+ printf(STDERR "dump and check can't be specified at the same time\n\n");
+ usage;
+ }
+ } elsif ( ( $ARGV[0] eq "-d" ) || ( $ARGV[0] eq "--debug" ) ) {
+ $debug=1;
+ $verbose=1;
+ } elsif ( ( $ARGV[0] eq "-v" ) || ( $ARGV[0] eq "--verbose" ) ) {
+ $verbose=1;
+ } else {
+ printf(STDERR "Unknown option: %s\n",$ARGV[0]);
+ usage;
+ }
+ shift(@ARGV);
+}
+if ($docheck) {
readconfigs();
-} elsif ($ARGV[0] eq "dump") {
+ exit(runcheck());
+} elsif ($dodump) {
readconfigs();
} else {
usage;
}
-
__END__
-DBENGINE BerkeleyDB4.2
More information about the Pkg-Cyrus-imapd-Debian-devel
mailing list