#!/usr/bin/perl -w
#
# Copyright (C) 2008 Joerg Dorchain <joerg@dorchain.net>
#
# recover a torrus-db in case of BerkeleyDB upgrades
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

require '/usr/share/torrus/conf_defaults/torrus-config.pl';

use strict;
use BerkeleyDB;

if ( not -d $Torrus::Global::dbHome ) { die "No such directory: $Torrus::Global::dbHome"; }

my $env = new BerkeleyDB::Env( -Home  => $Torrus::Global::dbHome,
		-Flags => (DB_CREATE | DB_RECOVER | DB_INIT_TXN | DB_INIT_LOCK),
		-Mode  => 0664, -ErrFile => *STDERR, -Verbose => 1 );
if( not defined($env) ) { die "Cannot create BerkeleyDB Environment: ".$BerkeleyDB::Error; }

# Use it only when it is implemented - checked with BerkeleyDB 0.34
# BerkeleyDB::env_remove (-Home  => $Torrus::Global::dbHome);
print "Recovery of $Torrus::Global::dbHome sucessful\n";
