1#!/bin/sh 2# 3# Run a basejob backup 4# then restore it. 5# 6 7TestName="base-job-test" 8JobName=backup 9. scripts/functions 10 11p() { 12 echo "##############################################" >> ${cwd}/tmp/log1.out 13 echo "$*" >> ${cwd}/tmp/log1.out 14 echo "##############################################" >> ${cwd}/tmp/log2.out 15 echo "$*" >> ${cwd}/tmp/log2.out 16 if is_debug; then 17 echo "##############################################" 18 echo "$*" 19 fi 20} 21 22# Directory to backup. 23# This directory will be created by setup_data(). 24# If set, $BackupDirectory will be used 25# as base directory by check_restore_diff(). 26# Don't use a "/" at the end of the directory path, 27# as it might cause problems 28# (filenames given as parameter to restore must match 100%. "//" are not identical with "/"). 29BackupDirectory="${tmp}/data" 30 31# Remove old configuration, working and tmp files. Setup the database. 32cleanup 33 34# Use a tgz to setup data to be backuped. 35# Data will be placed at "${tmp}/data". 36setup_data data/po.tgz 37 38copy_test_confs 39echo 's/backup_advance/base_backup/' > $tmp/s 40echo 's/Name = backup/Name = backup; Base = base_backup, backup/' >> $tmp/s 41sed -f $tmp/s $rscripts/bareos-dir.conf.accurate > $conf/bareos-dir.conf 42rm -f $tmp/s 43 44sed s/all,/all,saved,/ $conf/bareos-fd.conf > tmp/1 45cp tmp/1 $conf/bareos-fd.conf 46 47change_jobname BackupClient1 $JobName 48 49# add extra files 50mkdir -p ${BackupDirectory}/build/accurate 51mkdir -p ${BackupDirectory}/build/accurate/dirtest 52echo "test test" > ${BackupDirectory}/build/accurate/dirtest/hello 53echo "test test" > ${BackupDirectory}/build/accurate/xxx 54echo "test test" > ${BackupDirectory}/build/accurate/yyy 55echo "test test" > ${BackupDirectory}/build/accurate/zzz 56echo "test test" > ${BackupDirectory}/build/accurate/zzzzzz 57echo "test test" > ${BackupDirectory}/build/accurate/xxxxxx 58echo "test test" > ${BackupDirectory}/build/accurate/yyyyyy 59echo "test test" > ${BackupDirectory}/build/accurate/xxxxxxxxx 60echo "test test" > ${BackupDirectory}/build/accurate/yyyyyyyyy 61echo "test test" > ${BackupDirectory}/build/accurate/zzzzzzzzz 62echo ${BackupDirectory} > ${cwd}/tmp/file-list 63 64start_test 65 66cat <<END_OF_DATA >${cwd}/tmp/bconcmds 67@$out /dev/null 68messages 69label volume=TestVolume001 storage=File pool=Default 70messages 71END_OF_DATA 72 73run_bareos 74 75################################################################ 76p "Now do a backup using base backup" 77################################################################ 78 79echo ${cwd}/bin >> ${cwd}/tmp/file-list 80 81cat <<END_OF_DATA >${cwd}/tmp/bconcmds 82@$out ${cwd}/tmp/log1.out 83run job=base_backup level=base yes 84wait 85messages 86update volume=TestVolume001 volstatus=Used 87END_OF_DATA 88 89run_bconsole 90 91echo ${BackupDirectory}/build > ${cwd}/tmp/file-list 92 93cat <<END_OF_DATA >${cwd}/tmp/bconcmds 94@$out ${cwd}/tmp/log4.out 95label volume=TestVolume002 storage=File pool=Default 96run job=backup level=full yes 97wait 98messages 99@# 100@# now do a restore 101@# 102@$out ${cwd}/tmp/log2.out 103restore fileset=FS_TESTJOB where=${cwd}/tmp/bareos-restores select all done 104yes 105wait 106messages 107END_OF_DATA 108 109run_bconsole 110check_for_zombie_jobs storage=File 111 112check_two_logs 113check_restore_diff ${BackupDirectory}/build || exit 1 114 115rm -rf ${cwd}/tmp/bareos-restores 116 117grep -e 'FD Bytes Written: *0' ${cwd}/tmp/log4.out > /dev/null 118if [ $? -ne 0 ]; then 119 print_debug "ERROR: The first full job should have 0 byte in log4.out" 120 bstat=2 121fi 122 123grep -e 'Using BaseJobId(s): 1$' ${cwd}/tmp/log4.out > /dev/null 124if [ $? -ne 0 ]; then 125 print_debug "ERROR: The first full job should use only jobid=1 as basejob" 126 bstat=2 127fi 128 129################################################################ 130p "Now do a backup after making few changes" 131################################################################ 132 133rm ${BackupDirectory}/build/accurate/yyyyyy # delete a file 134rm -rf ${BackupDirectory}/build/accurate/dirtest 135 136cat <<END_OF_DATA >${cwd}/tmp/bconcmds 137@$out ${cwd}/tmp/log1.out 138update volume=TestVolume002 volstatus=Used 139label volume=TestVolume003 storage=File pool=Default 140run job=backup level=incremental yes 141wait 142messages 143list files jobid=4 144@# 145@# now do a restore 146@# 147@$out ${cwd}/tmp/log2.out 148restore fileset=FS_TESTJOB where=${cwd}/tmp/bareos-restores select all done 149yes 150wait 151messages 152END_OF_DATA 153 154run_bconsole 155check_for_zombie_jobs storage=File 156 157check_two_logs 158check_restore_diff || exit 1 159check_files_written ${cwd}/tmp/log1.out 4 160 161rm -rf ${cwd}/tmp/bareos-restores 162 163################################################################ 164p "Test the job purge" 165################################################################ 166cat <<END_OF_DATA >${cwd}/tmp/bconcmds 167@$out ${cwd}/tmp/log3.out 168sql 169SELECT count(*) FROM BaseFiles; 170 171purge volume=TestVolume002 172messages 173sql 174SELECT count(*) FROM BaseFiles; 175 176END_OF_DATA 177 178run_bconsole 179 180grep -e ' 0 *|' ${cwd}/tmp/log3.out > /dev/null 181if [ $? -ne 0 ]; then 182 print_debug "ERROR: Can't purge the base job" 183 estat=1 184fi 185 186 187################################################################ 188p "Test list commands" 189################################################################ 190 191touch ${BackupDirectory}/build/po/fr.po 192 193cat <<END_OF_DATA >${cwd}/tmp/bconcmds 194run level=full job=backup yes 195wait 196messages 197@out ${cwd}/tmp/log5.out 198list basefiles jobid=6 199@out ${cwd}/tmp/log6.out 200list files jobid=6 201messages 202END_OF_DATA 203 204run_bconsole 205 206grep "po/fr.po^" ${cwd}/tmp/log5.out > /dev/null 207if [ $? -eq 0 ]; then 208 print_debug "ERROR: Should not display fr.po as basefile" 209 estat=2 210fi 211 212export bstat dstat estat 213 214stop_bareos 215end_test 216