# this is no funky script, let's use strict and Carp use strict; use Carp; use Data::Dumper; use vars qw /$CONFIG $FILE/; $CONFIG = undef; $FILE = shift (@ARGV) or die "Usage: db2file.pl "; # let's parse install.conf to find out where MKDoc libraries # are installed on the system BEGIN { $CONFIG = {}; open FP, "<../install.conf" or die "Cannot read-open ../install.conf"; while (my $string = ) { chomp ($string); # if the line starts with a comment, then it's all a comment next if ($string =~ /^\#.*/); # has this line got comments? if ($string =~ /(?{$key} = $val; } else { if ($string =~ /\S+(\s+)\S+/) { my ($key, $val) = $string =~ /(.*?)\s+(.*)/; $val =~ s/\s+$//; $CONFIG->{$key} = $val; } else { my $key = $string; my $val = 1; $CONFIG->{$key} = $val; } } } close FP; # unshift @INC to add MKDoc install dir unshift @INC, $CONFIG->{MKDOC_DIR}; } # try to import required modules eval { use lib::Config; use lib::Template; use lib::Exception; use flo::Category; use lib::Config; use lib::sql::type::ALL; use lib::sql::Table; }; die $@ if (defined $@ and $@); # finally (!), let us do the job main(); sub main { # first of all, we need to load the database state lib::sql::Table->load_state ('../su'); # let's build a hash that will contain all the table names my $database = {}; foreach my $table_name (keys %{$lib::sql::Table::DATABASE}) { my $table = lib::sql::Table->table ($table_name); if ($table_name eq 'Document') { my @list = (); push @list, $table->get (1); $database->{$table_name} = []; while (@list) { my $document = shift (@list); push @list, $document->Children; push @{$database->{$table_name}}, $document; } } else { $database->{$table_name} = $table->search->fetch_all; } } # we don't need the Document_Index table as it will be restored # when we reinsert documents anyway delete $database->{Document_Index}; delete $database->{Session}; # now we want to dump that data onto disk just in case we # screw up print "Dumping database...\n"; my $data_dump = Dumper ($database); open FP, ">$FILE" or croak "Cannot write-open $FILE"; print FP $data_dump; close FP; } 1;