Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
added truncate-command-test
Browse files Browse the repository at this point in the history
  • Loading branch information
joergsteffens committed Nov 16, 2016
1 parent 2ea4515 commit db91769
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README
Expand Up @@ -60,7 +60,7 @@ Running the disk based tests:

You can run all the disk based tests by doing:

./do_file
./do_disk

The disk based tests are totally separate from any production
system, provided you have configured the database appropriately
Expand Down
3 changes: 2 additions & 1 deletion tests/1-example-test
Expand Up @@ -64,8 +64,9 @@ messages
quit
END_OF_DATA

# Start the bareos daemon
# Start the bareos daemons
# and run the bconsole commands from ${tmp}/bconcmds
# Further bconsole commands can be executed by "run_bconsole".
run_bareos

# verify that all are terminated
Expand Down
106 changes: 106 additions & 0 deletions tests/truncate-command-test
@@ -0,0 +1,106 @@
#!/bin/sh

. scripts/functions

#
# Test the truncate command
#

get_filesize()
{
stat --printf="%s" "$1"
}

# Define the Name of the test as "TestName".
# Should be the same as the filename, therefore we use the filename as default.
TestName="`basename $0`"

# set other test specific variables
Client=bareos-fd
JobName=backup-bareos-fd

# a truncated volume has not the size 0, but is at least smaller than this (default block size)
MinVolumeSize=65536
VolumeName=TestVolume001

# Directory to backup.
# This example uses a subdirectory of the bareos source/build directory,
# that contains some file but isn't to large.
BackupDirectory="${cwd}/build/src/tests/"

# Remove old configuration, working and tmp files. Setup the database.
cleanup

# Config files will be copied to required location.
# Base configuration files come from the
# configs/BASE/ directory, see
# configs/BASE/README.txt for an overview of the provides resources.
# Store your additonal resources to
# configs/$TestName.
# It is also possible to overwrite resources from configs/BASE.
# If you define a full config file (instead of config files for individual resources),
# only these will be taken.
copy_configs

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list

# start the test
start_test

# ${tmp}/bconcmds lists the bconsole commands executed by "run_bareos"
# create a volume and put data on it.
cat <<END_OF_DATA >${tmp}/bconcmds
messages
@$out ${tmp}/log1.out w
label storage=File1 volume=${VolumeName} pool=Default
run job=$JobName storage=File1 yes
wait
messages
END_OF_DATA

# Start the bareos daemons
# and run the bconsole commands from ${tmp}/bconcmds
run_bareos

# get size of backup job
#sed -r -n -e 's/ *SD Bytes Written: *([0-9,]*) .*/\1/p' tmp/log1.out | sed s/,//
VolumeSizeWithJob=`get_filesize ${tmp}/${VolumeName}`

# do some manual testing
if [ ${VolumeSizeWithJob} -lt ${MinVolumeSize} ]; then
set_error "Volume size: ${VolumeSizeWithJob} < ${MinVolumeSize}. Something went wrong with the backup."
fi


cat <<END_OF_DATA >${tmp}/bconcmds2
@$out ${tmp}/log2.out w
purge volume=${VolumeName}
truncate volstatus=Purged volume=${VolumeName} yes
messages
END_OF_DATA

run_bconsole ${tmp}/bconcmds2

# verify that all are terminated
check_for_zombie_jobs storage=File1 client=${Client}

# stop bareos
stop_bareos

# check tmp/log1.out and tmp/log2.out for errors
check_two_logs

VolumeSizeAfterTruncate=`get_filesize ${tmp}/${VolumeName}`

# do some manual testing
if [ ${VolumeSizeAfterTruncate} -gt ${MinVolumeSize} ]; then
set_error "Volume size: ${VolumeSizeAfterTruncate} > ${MinVolumeSize}. Something went wrong with the truncate command."
fi

printf "Volume path: %s\n" ${tmp}/${VolumeName}
printf "Size before truncate: %d\n" ${VolumeSizeWithJob}
printf "Size after truncate: %d\n" ${VolumeSizeAfterTruncate}

# end tests and check for error codes
end_test

0 comments on commit db91769

Please sign in to comment.