proc backup { {nentries 1000} } {
source ./include.tcl
global util_path
set omethod "-btree"
set testfile "foo.db"
set backupdir "backup"
set log_size 20000
set env_flags " -create -txn -home $testdir -log_max $log_size"
set db_flags " -create $omethod -auto_commit $testfile "
foreach option { checkpoint nocheckpoint } {
if { $option == "checkpoint" } {
set c "c"
set msg "with checkpoint"
} else {
set c ""
set msg "without checkpoint"
}
puts "Backuptest $msg."
env_cleanup $testdir
env_cleanup $backupdir
set env [eval {berkdb_env} $env_flags]
set db [eval {berkdb_open} -env $env $db_flags]
set txn [$env txn]
populate $db $omethod $txn $nentries 0 0
$txn commit
set files [glob -nocomplain $backupdir/*]
error_check_good no_files [llength $files] 0
puts "\tBackuptest.a: Hot backup to directory $backupdir."
if {[catch { eval exec $util_path/db_hotbackup\
-${c}vh $testdir -b $backupdir } res ] } {
error "FAIL: $res"
}
set logfiles [glob $backupdir/log*]
error_check_bad found_logs [llength $logfiles] 0
error_check_good found_db [file exists $backupdir/$testfile] 1
error_check_good db_close [$db close] 0
error_check_good env_close [$env close] 0
env_cleanup $testdir
puts "\tBackuptest.b: Hot backup with data_dir."
file mkdir $testdir/data1
error_check_good db_data_dir\
[file exists $testdir/data1/$testfile] 0
set env [eval {berkdb_env_noerr} $env_flags -data_dir data1]
set db [eval {berkdb_open} -env $env $db_flags]
set txn [$env txn]
populate $db $omethod $txn $nentries 0 0
$txn commit
error_check_good db_data_dir\
[file exists $testdir/data1/$testfile] 1
set msg2 "cannot specify -d and -c"
if { $option == "checkpoint" } {
catch {eval exec $util_path/db_hotbackup\
-${c}vh $testdir -b $backupdir\
-d $testdir/data1} res
error_check_good c_and_d [is_substr $res $msg2] 1
} else {
if {[catch {eval exec $util_path/db_hotbackup\
-${c}vh $testdir -b $backupdir\
-d $testdir/data1} res] } {
error "FAIL: $res"
}
error_check_good db_backup\
[file exists $backupdir/$testfile] 1
set logfiles [glob $backupdir/log*]
error_check_bad logs_backed_up [llength $logfiles] 0
}
puts "\tBackuptest.c: Update existing hot backup."
set txn [$env txn]
populate $db $omethod $txn [expr $nentries * 2] 0 0
$txn commit
if { $option == "checkpoint" } {
catch {eval exec $util_path/db_hotbackup\
-${c}vuh $testdir -b backup -d $testdir/data1} res
error_check_good c_and_d [is_substr $res $msg2] 1
} else {
if {[catch {eval exec $util_path/db_hotbackup\
-${c}vuh $testdir -b backup\
-d $testdir/data1} res] } {
error "FAIL: $res"
}
set newlogfiles [glob $backupdir/log*]
error_check_bad more_logs $newlogfiles $logfiles
}
puts "\tBackuptest.d: Hot backup with full path."
set fullpath [pwd]
if { $option == "checkpoint" } {
catch {eval exec $util_path/db_hotbackup\
-${c}vh $testdir -b backup\
-d $fullpath/$testdir/data1} res
error_check_good c_and_d [is_substr $res $msg2] 1
} else {
if {[catch {eval exec $util_path/db_hotbackup\
-${c}vh $testdir -b backup\
-d $fullpath/$testdir/data1} res] } {
error "FAIL: $res"
}
}
error_check_good db_close [$db close] 0
error_check_good env_close [$env close] 0
env_cleanup $testdir
env_cleanup $backupdir
puts "\tBackuptest.e: Hot backup with DB_CONFIG."
backuptest_makeconfig
set env [eval {berkdb_env_noerr} $env_flags]
set db [eval {berkdb_open} -env $env $db_flags]
set txn [$env txn]
populate $db $omethod $txn $nentries 0 0
$txn commit
if { $option == "checkpoint" } {
catch {eval exec $util_path/db_hotbackup\
-${c}vh $testdir -b $backupdir -l $testdir/logs\
-d $testdir/data1} res
error_check_good c_and_d [is_substr $res $msg2] 1
} else {
if {[catch {eval exec $util_path/db_hotbackup\
-${c}vh $testdir -b $backupdir -l $testdir/logs\
-d $testdir/data1} res] } {
error "FAIL: $res"
}
error_check_good db_backup\
[file exists $backupdir/$testfile] 1
set logfiles [glob $backupdir/log*]
error_check_bad logs_backed_up [llength $logfiles] 0
}
set txn [$env txn]
populate $db $omethod $txn [expr $nentries * 2] 0 0
$txn commit
puts "\tBackuptest.f:\
Hot backup update with DB_CONFIG."
if { $option == "checkpoint" } {
catch {eval exec $util_path/db_hotbackup\
-${c}vuh $testdir -b backup -l $testdir/logs\
-d $testdir/data1} res
error_check_good c_and_d [is_substr $res $msg2] 1
} else {
if {[catch {eval exec $util_path/db_hotbackup\
-${c}vuh $testdir -b backup -l $testdir/logs\
-d $testdir/data1} res] } {
error "FAIL: $res"
}
set newlogfiles [glob $backupdir/log*]
error_check_bad more_logs $newlogfiles $logfiles
}
puts "\tBackuptest.g:\
Hot backup with DB_CONFIG (non-update)."
if { [catch { eval exec $util_path/db_hotbackup\
-${c}vh $testdir -b $backupdir -D } res] } {
error "FAIL: $res"
}
error_check_good db_close [$db close] 0
error_check_good env_close [$env close] 0
}
}
proc backuptest_makeconfig { } {
source ./include.tcl
file mkdir $testdir/logs
file mkdir $testdir/data1
set cid [open $testdir/DB_CONFIG w]
puts $cid "set_lg_dir logs"
puts $cid "set_data_dir data1"
close $cid
}