1#!/bin/sh 2 3. scripts/functions 4 5 6os=`uname -s` 7if [ "$os" = "FreeBSD" ]; then 8 SED=`which gsed` 9 if [ -z $SED ]; then 10 echo "gsed is required on FreeBSD for this test" 11 exit 1 12 fi 13else 14 SED=sed 15fi 16 17 18# Define the Name of the test as "TestName". 19# Should be the same as the filename, therefore we use the filename as default. 20TestName="`basename $0`" 21 22# set other test specific variables 23Client=bareos-fd 24JobName=backup-bareos-fd 25BackupJobIds="1,2" 26BvfsPathId="b201" 27 28# Directory to backup. 29# This directory will be created by setup_data(). 30BackupDirectory="${tmp}/data" 31BackupFileExtra=${BackupDirectory}/extrafile.txt 32 33# Remove old configuration, working and tmp files. Setup the database. 34cleanup 35 36# Config files will be copied to required location. 37# Base configuration files come from the 38# configs/BASE/ directory, see 39# configs/BASE/README.txt for an overview of the provides resources. 40# Store your additonal resources to 41# configs/$TestName. 42# It is also possible to overwrite resources from configs/BASE. 43# If you define a full config file (instead of config files for individual resources), 44# only these will be taken. 45copy_configs 46 47# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list". 48echo "${BackupDirectory}" >${tmp}/file-list 49 50# Use a tgz to setup data to be backed up. 51# Data will be placed at "${tmp}/data/". 52setup_data data/small.tgz 53 54# start the test 55start_test 56 57# activate bpipe-fd plugin 58enable_plugin bpipe-fd 59 60echo "Test Content 1" > ${BackupFileExtra} 61 62# ${tmp}/bconcmds lists the bconsole commands executed by "run_bareos" 63cat <<END_OF_DATA >${tmp}/bconcmds 64messages 65@$out ${tmp}/log-backup1.out w 66label storage=File1 pool=Default volume=TestVolume001 67run job=$JobName fileset=bpipe-fileset storage=File1 yes 68wait 69messages 70quit 71END_OF_DATA 72 73# Start the bareos daemons 74# and run the bconsole commands from ${tmp}/bconcmds 75# Further bconsole commands can be executed by "run_bconsole". 76run_bareos 77check_log ${tmp}/log-backup1.out 78 79 80# modify file and rerun backup 81echo "Test Content 2" >> ${BackupFileExtra} 82 83cat <<END_OF_DATA >${tmp}/bconcmds 84@$out ${tmp}/log-backup2.out w 85run job=$JobName fileset=bpipe-fileset storage=File1 yes 86wait 87messages 88quit 89END_OF_DATA 90 91run_bconsole 92check_log ${tmp}/log-backup2.out 93 94 95# use bvfs to restore 96cat <<END_OF_DATA >${tmp}/bconcmds 97@# 98@# bvfs 99@# 100.bvfs_update 101@$out ${tmp}/log-bvfs-jobids.out w 102.bvfs_get_jobids jobid=2 103 104@$out ${tmp}/log-bvfs-get-root-path.out w 105.bvfs_lsdir jobid=${BackupJobIds} path= 106 107@$out ${tmp}/log-bvfs-get-root-path-offset.out w 108.bvfs_lsdir jobid=${BackupJobIds} path= offset=1000 limit=1000 109 110@$out ${tmp}/log-bvfs-lsdir-root.out w 111.bvfs_lsdir jobid=${BackupJobIds} path=/ 112 113@$out ${tmp}/log-bvfs-lsdir-BackupDirectory.out w 114.bvfs_lsdir jobid=${BackupJobIds} path=${BackupDirectory}/ 115 116@$out ${tmp}/log-bvfs-lsfiles-BackupDirectory.out w 117@#.bvfs_lsfiles jobid=${BackupJobIds} pathid=1 118.bvfs_lsfiles jobid=${BackupJobIds} path=${BackupDirectory}/ 119 120@$out ${tmp}/log-bvfs-lsfiles-BackupDirectory-limit1.out w 121.bvfs_lsfiles jobid=${BackupJobIds} path=${BackupDirectory}/ offset 0 limit 1 122 123@$out ${tmp}/log-bvfs-versions-extrafile.out w 124.bvfs_versions jobid=0 client=${Client} path=${BackupDirectory}/ fname=extrafile.txt 125 126@$out ${tmp}/log-bvfs-lsfiles-bpipe-directory.out w 127.bvfs_lsfiles jobid=${BackupJobIds} path=@bpipe@/ 128END_OF_DATA 129 130run_bconsole 131LOG=${tmp}/log-bvfs-lsdir-BackupDirectory.out 132# expect: 133# 1 0 19 1 x GoHK EHt C GHH GHH A BAA BAA I BWDNOj BZwlgI BZwlgI A A C . 134# 2 0 0 0 A A A A A A A A A A A A A A .. 135# need to get dirid of "." 136DirId=$(${SED} -n 's/^\([0-9]\+\)\W.*[a-zA-Z]\+\W\.$/\1/p' $LOG) 137if [ -z "$DirId" ]; then 138 set_error "failed to find DirId of backup directory (using '.bvfs_lsdir path=${BackupDirectory}/')." 139fi 140 141cat <<END_OF_DATA >${tmp}/bconcmds 142@$out ${tmp}/log-bvfs-restore.out w 143@# 144@# now do a restore 145@# 146@#.bvfs_restore path=b201 fileid=numlist dirid=numlist hardlink=numlist path=b201 147.bvfs_restore path=${BvfsPathId} jobid=${BackupJobIds} dirid=${DirId} 148 149restore client=${Client} where=${tmp}/bareos-restores storage=File1 file=?${BvfsPathId} yes 150wait 151messages 152 153@$out ${tmp}/log-bvfs-cache.out w 154.sql query="SELECT count(*) FROM Job WHERE HasCache!=0;" 155.sql query="SELECT count(*) FROM PathHierarchy;" 156.sql query="SELECT count(*) FROM PathVisibility;" 157 158@$out ${tmp}/log-bvfs-cleanup.out w 159.sql query="SELECT count(*) FROM ${BvfsPathId};" 160.bvfs_cleanup path=${BvfsPathId} 161@# table should not exist any more, so query will fail. Don't log. 162@$out /dev/null 163.sql query="SELECT count(*) FROM ${BvfsPathId};" 164 165@$out ${tmp}/log-bvfs-clear-cache.out w 166.bvfs_clear_cache yes 167 168@$out ${tmp}/log-bvfs-cleared-cache-hascache.out w 169.sql query="SELECT count(*) FROM Job WHERE HasCache!=0;" 170@$out ${tmp}/log-bvfs-cleared-cache-PathHierarchy.out w 171.sql query="SELECT count(*) FROM PathHierarchy;" 172@$out ${tmp}/log-bvfs-cleared-cache-PathVisibility.out w 173.sql query="SELECT count(*) FROM PathVisibility;" 174 175quit 176END_OF_DATA 177 178run_bconsole 179 180# verify that all are terminated 181check_for_zombie_jobs storage=File1 client=${Client} 182 183# stop bareos 184stop_bareos 185 186# check tmp/log1.out and tmp/log2.out for errors 187#check_two_logs 188 189LOG=${tmp}/log-bvfs-jobids.out 190check_log ${LOG} 191# expect: 1,2 192if ! grep -q "^[0-9,]*2$" ${LOG}; then 193 set_error "failed to find required job ids." 194fi 195 196LOG=${tmp}/log-bvfs-get-root-path.out 197check_log ${LOG} 198# expect: 199# 10 0 0 A A A A A A A A A A A A A A . 200# 9 0 0 A A A A A A A A A A A A A A / 201# 8 0 0 A A A A A A A A A A A A A A @bpipe@/ 202if ! grep -q "\W/$" ${LOG}; then 203 set_error "root directory not found (using '.bvfs_lsdir path=')." 204fi 205 206if ! grep -q "\W@bpipe@/$" ${LOG}; then 207 set_error "@bpipe@ plugin directory not found (using '.bvfs_lsdir path=')." 208fi 209 210LOG=${tmp}/log-bvfs-get-root-path-offset.out 211check_log ${LOG} 212# expect: empty file, as offset larger than number of dirs 213dirs=`grep "^[0-9]\+\W" ${LOG} | wc -l` 214if [ "$dirs" -gt 0 ]; then 215 set_error "result should be empty (using '.bvfs_lsdir path= offset=1000')." 216fi 217 218 219LOG=${tmp}/log-bvfs-lsdir-root.out 220check_log ${LOG} 221# expect: 222# 9 0 0 0 A A A A A A A A A A A A A A . 223# 10 0 0 0 A A A A A A A A A A A A A A .. 224# 8 0 0 0 A A A A A A A A A A A A A A TOP_DIRECTORY 225dirs=`grep "^[0-9]\+\W" ${LOG} | wc -l` 226if [ "$dirs" -lt 3 ]; then 227 set_error "failed to find top directory (using '.bvfs_lsdir path=/')." 228fi 229 230LOG=${tmp}/log-bvfs-lsdir-BackupDirectory.out 231check_log ${LOG} 232# expect: 233# 1 0 19 1 x GoHK EHt C GHH GHH A BAA BAA I BWDNOj BZwlgI BZwlgI A A C . 234# 2 0 0 0 A A A A A A A A A A A A A A .. 235if ! grep -q "^[0-9]\+\W.*\W\.$" ${LOG}; then 236 set_error "failed to find backup directory (using '.bvfs_lsdir path=${BackupDirectory}/')." 237fi 238 239LOG=${tmp}/log-bvfs-lsfiles-BackupDirectory.out 240check_log ${LOG} 241if ! grep -q "\Wextrafile.txt" ${LOG}; then 242 set_error "file not found using .bvfs_lsfiles." 243fi 244 245LOG=${tmp}/log-bvfs-lsfiles-BackupDirectory-limit1.out 246check_log ${LOG} 247files=`grep "^[0-9]\+\W" ${LOG} | wc -l` 248if [ $files -ne 1 ]; then 249 set_error "expected 1 file, found ${files}." 250fi 251 252LOG=${tmp}/log-bvfs-versions-extrafile.out 253check_log ${LOG} 254versions=`grep "^[0-9]\+\W" ${LOG} | wc -l` 255if [ $versions -ne 2 ]; then 256 set_error "expected 2 versions of file ${BackupFileExtra}, found ${versions}." 257fi 258 259LOG=${tmp}/log-bvfs-lsfiles-bpipe-directory.out 260check_log ${LOG} 261if ! grep -q "\Wbpipe-dir-as-root-test.txt" ${LOG}; then 262 set_error "bpipe plugin result file not found using .bvfs_lsfiles." 263fi 264 265LOG=${tmp}/log-bvfs-restore.out 266check_log ${LOG} 267# check for differences between original files and restored files 268check_restore_diff ${BackupDirectory} 269 270# do some manual testing 271if [ ! -d ${BackupDirectory} ]; then 272 set_error "directory ${BackupDirectory} does not exists any more." 273fi 274 275LOG=${tmp}/log-bvfs-cleared-cache-hascache.out 276check_log ${LOG} 277# expect: 278# .sql query="SELECT count(*) FROM Job WHERE HasCache!=0;" 279# +----------+ 280# | count(*) | 281# +----------+ 282# | 0 | 283# +----------+ 284# 285# Get the 5. line and remove all "|" and " " 286COUNT=`${SED} -e '5!d' -e 's/|//g' -e 's/ //g' $LOG` 287if [ "${COUNT}" -ne "0" ]; then 288 set_error "after .bvfs_clear_cache HasCache should be 0, not ${COUNT}." 289fi 290 291LOG=${tmp}/log-bvfs-cleared-cache-PathHierarchy.out 292check_log ${LOG} 293COUNT=`${SED} -e '5!d' -e 's/|//g' -e 's/ //g' $LOG` 294if [ "${COUNT}" -ne "0" ]; then 295 set_error "after .bvfs_clear_cache PathHierarchy table should be empty (but has ${COUNT} entries)." 296fi 297 298LOG=${tmp}/log-bvfs-cleared-cache-PathVisibility.out 299check_log ${LOG} 300COUNT=`${SED} -e '5!d' -e 's/|//g' -e 's/ //g' $LOG` 301if [ "${COUNT}" -ne "0" ]; then 302 set_error "after .bvfs_clear_cache PathVisibility table should be empty (but has ${COUNT} entries)." 303fi 304 305# end tests and check for error codes 306end_test 307