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

Commit

Permalink
fix and active tests that creates sparse files
Browse files Browse the repository at this point in the history
replaces the gigaslam tool by scripts/create_sparse_file.sh,
to be able to create sparse files at arbitrary sizes.
Creating a sparse file of 100M (real size about 8K).
  • Loading branch information
joergsteffens committed Dec 3, 2016
1 parent b41ce92 commit 721c56e
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 89 deletions.
7 changes: 2 additions & 5 deletions all-disk-tests
Expand Up @@ -45,11 +45,8 @@ rm -f dumps/*
./run tests/fileregexp-test
./run tests/backup-to-null
./run tests/regexwhere-test
# The following two can uses *lots* of disk space
# so they are normally turned off, but if you have
# at least two GB free, you can run them
#./run tests/sparse-encrypt-test
#./run tests/gigaslam-sparse-test
./run tests/sparse-file-test
./run tests/sparse-encrypt-test
./run tests/differential-test
./run tests/four-concurrent-jobs-test
./run tests/four-jobs-test
Expand Down
20 changes: 20 additions & 0 deletions scripts/create_sparse_file.sh
@@ -0,0 +1,20 @@
#!/bin/sh

filename=${1:-sparse.dat}
size=${2:-100M}

echo "start" > $filename
dd if=/dev/zero of=$filename bs=1 count=0 seek=$size 2>/dev/null
echo "end" >> $filename

size="`du --block-size=1 --apparent-size ${filename} | cut -f 1`"
realsize="`du --block-size=1 ${filename} | cut -f 1`"

printf "$filename created.\n"
printf "size=%s\n" "$size"
printf "realsize=%s\n" "$realsize"

if ! [ "$realsize" -lt "$size" ]; then
printf "ERROR: realsize has to be smaller than size.\n"
exit 1
fi
1 change: 1 addition & 0 deletions scripts/functions
Expand Up @@ -160,6 +160,7 @@ set_error()
{
estat=9
echo "ERROR: $@" >> $tmp/err.log
echo "ERROR: $@"
}

check_files_written()
Expand Down
61 changes: 0 additions & 61 deletions tests/gigaslam-sparse-test

This file was deleted.

60 changes: 37 additions & 23 deletions tests/sparse-encrypt-test
Expand Up @@ -3,25 +3,39 @@
# Run a simple backup with encryption and a real sparse file.
#
TestName="sparse-encrypt-test"
JobName=Crypto
JobName=SparseTest
. scripts/functions

scripts/cleanup
scripts/copy-crypto-confs
echo "${cwd}/build" >${cwd}/tmp/file-list
cd ${cwd}/build/src/tools
./gigaslam

# 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/"

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

mkdir -p "${BackupDirectory}"
SPARSEFILE="${BackupDirectory}/gigaslam.gif"

# create a sparse file
scripts/create_sparse_file.sh ${SPARSEFILE} 100M
if [ $? != 0 ]; then
echo "Execute of ${cwd}/build/src/tools/gigaslam failed."
rm -f ${cwd}/build/src/tools/gigaslam.gif
exit 1
set_error "create_sparse_file failed."
rm -f ${SPARSEFILE}
exit 1
fi

if ! [ -e "${SPARSEFILE}" ]; then
set_error "Failed to create sparse file."
exit 1
fi
cd ${cwd}

change_jobname SparseTest $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
cat >${cwd}/tmp/bconcmds <<END_OF_DATA
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
Expand All @@ -47,23 +61,23 @@ quit
END_OF_DATA

run_bareos
sleep 2
check_for_zombie_jobs storage=File
stop_bareos

if [ ! -f ${cwd}/tmp/bareos-restores/${cwd}/build/src/tools/gigaslam.gif ]; then
echo "============= file gigaslam.gif was not restored ======="
size=0
else
size=`du ${cwd}/tmp/bareos-restores/${cwd}/build/src/tools/gigaslam.gif | cut -f 1`
if [ $size -gt 120 ]; then
echo "========== restored sparse file: gigaslam.gif too big ========="
echo " size is ${size}K it should be 120K"
fi
size_orig=`du ${SPARSEFILE} | cut -f 1`
size=`du ${cwd}/tmp/bareos-restores/${SPARSEFILE} | cut -f 1`
if [ -z "$size" ]; then
set_error "Failed to determine size of restored sparse file."
elif [ $size -gt 120 ]; then
set_error "Restored sparse file ${SPARSEFILE} is too big (${size}K > 120K)"
fi

print_debug "size orig: $size_orig"
print_debug "size restored: $size"

check_two_logs
check_restore_diff
check_restore_diff "${BackupDirectory}"

rm -f ${SPARSEFILE}

end_test
rm -f ${cwd}/build/src/tools/gigaslam.gif
rm -f ${cwd}/build/gigaslam.gif
85 changes: 85 additions & 0 deletions tests/sparse-file-test
@@ -0,0 +1,85 @@
#!/bin/sh
#
# Run a simple backup of the Bareos build directory using the Sparse option
# then restore it.
#
TestName="gigaslam-sparse-test"
JobName=SparseTest
#JobName=SparseCompressedTest

. scripts/functions

scripts/cleanup
scripts/copy-test-confs

# 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/"

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

mkdir -p "${BackupDirectory}"

SPARSEFILE="${BackupDirectory}/gigaslam.gif"

# create a sparse file
scripts/create_sparse_file.sh ${SPARSEFILE} 100M
if [ $? != 0 ]; then
set_error "create_sparse_file failed."
rm -f ${SPARSEFILE}
exit 1
fi

if ! [ -e "${SPARSEFILE}" ]; then
set_error "Failed to create sparse file."
exit 1
fi

start_test

cat >${cwd}/tmp/bconcmds <<END_OF_DATA
@$out /dev/null
messages
@$out ${cwd}/tmp/log1.out
label storage=File volume=TestVolume001
run job=$JobName yes
wait
messages
list volumes
@#
@# now do a restore
@#
@$out ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bareos-restores select storage=File
unmark *
mark *
done
yes
wait
messages
quit
END_OF_DATA

run_bareos
check_for_zombie_jobs storage=File
stop_bareos

size_orig=`du ${SPARSEFILE} | cut -f 1`
size=`du ${cwd}/tmp/bareos-restores/${SPARSEFILE} | cut -f 1`
if [ -z "$size" ]; then
set_error "Failed to determine size of restored sparse file."
elif [ $size -gt 120 ]; then
set_error "Restored sparse file ${SPARSEFILE} is too big (${size}K > 120K)"
fi

print_debug "size orig: $size_orig"
print_debug "size restored: $size"

check_two_logs
check_restore_diff "${BackupDirectory}"

rm -f ${SPARSEFILE}

end_test

0 comments on commit 721c56e

Please sign in to comment.