#!/usr/bin/perl -w # # This script takes as its parameters a list of Berkeley DB # file(s) which are stored with the DB_BTREE algorithm. It # will back them up using the .bak extension and create # instead DBMs with the same records but stored using the # DB_HASH algorithm # # Usage: btree2hash.pl filename(s) use strict; use DB_File; use Fcntl; # @ARGV checks die "Usage: btree2hash.pl filename(s))\n" unless @ARGV; for my $filename (@ARGV) { die "Can't find $filename: $!" unless -e $filename and -r _; # First backup the file rename "$filename", "$filename.btree" or die "can't rename $filename with $filename.btree: $!"; # tie both dbs (db_hash is a fresh one!) tie my %btree , 'DB_File',"$filename.btree", O_RDWR|O_CREAT, 0660, $DB_BTREE or die "Can't tie $filename.btree: $!"; tie my %hash , 'DB_File',"$filename" , O_RDWR|O_CREAT, 0660, $DB_HASH or die "Can't tie $filename: $!"; # copy DB %hash = %btree; # untie untie %btree; untie %hash;