From: Michal Rakowski Date: Tue, 31 Aug 2021 11:01:35 +0000 (+0200) Subject: regress: add append and immutable volume tests X-Git-Tag: Beta-15.0.0~836 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3a2d52d06463222854748dd0ffad41605daf2f4;p=thirdparty%2Fbacula.git regress: add append and immutable volume tests WARNING: To be able to run this test you have to be sure that Bacula is configured with systemd support (--with-systemd) and that correct bacula-sd.service exists in your systemd directory. Also see platforms/systed. --- diff --git a/regress/all-vol-append-immutable-tests b/regress/all-vol-append-immutable-tests new file mode 100755 index 000000000..7f2ca9764 --- /dev/null +++ b/regress/all-vol-append-immutable-tests @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Append and Immutable volumes test suite +# +echo " " +echo " " >>test.out +echo "Start Append Immutable Volume tests " +echo "Start Append Immutable Volume tests" >>test.out + +./run tests/volume-append-test +./run tests/volume-append-many-vols-test +./run tests/volume-immutable-test + +echo "End Append Immutable Volume tests " +echo "End Append Immutable Volume tests" >>test.out diff --git a/regress/scripts/create_sed b/regress/scripts/create_sed index 19ca52ec4..2ce9335bf 100755 --- a/regress/scripts/create_sed +++ b/regress/scripts/create_sed @@ -44,6 +44,10 @@ win32_wsep_file=`echo $WIN32_FILE | sed -e 's=/=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ echo "s%@remotehostaddr@%${REMOTE_HOST_ADDR}%g" >${out} echo "s%@remotedirname@%${REMOTE_DIR_NAME}%g" >>${out} echo "s%@sbindir@%${bin}%g" >>${out} +echo "s%@libdir@%${bin}%g" >>${out} +echo "s%@sysconfdir@%${bin}%g" >>${out} +echo "s%@sd_user@%`whoami`%g" >>${out} +echo "s%@sd_group@%`id -g -n`%g" >>${out} echo "s%@scriptdir@%${scripts}%g" >>${out} echo "s%@working_dir@%${working}%g" >>${out} echo "s%@piddir@%${working}%g" >>${out} diff --git a/regress/tests/volume-append-many-vols-test b/regress/tests/volume-append-many-vols-test new file mode 100755 index 000000000..0c9d49ca6 --- /dev/null +++ b/regress/tests/volume-append-many-vols-test @@ -0,0 +1,113 @@ +#!/bin/sh +# +# Copyright (C) 2000-2021 Kern Sibbald +# License: BSD 2-Clause; see file LICENSE-FOSS +# +# Test if Volumes created automatically by bacula during backup +# are set with the APPEND flag, so that it cannot be overwritten accidentally. +# This test creates temporary bacula-sd.service file so that we can run SD +# as systemd service. +# +TestName="volume-append-many-vols-test" +JobName=append + +. scripts/functions + +require_linux + +scripts/cleanup +scripts/copy-confs + +cleanup() +{ + #Stop the daemon if the test was interrupted in the middle of a run + sudo systemctl stop test-bacula-sd > /dev/null 2>&1 + #Disable the service + sudo systemctl disable test-bacula-sd + #Clear volume attributes if needed + sudo chattr -ia tmp/* +} + +trap 'cleanup' EXIT INT TERM + +# Create temporary bacula-sd.service file so that we can run SD as systemd service +scripts/create_sed +sed -f ${tmp}/sed_tmp ${cwd}/build/platforms/systemd/bacula-sd.service.in > ${tmp}/test-bacula-sd.service +sudo systemctl enable ${tmp}/test-bacula-sd.service + +# Zap out any schedule in default conf file so that +# it doesn't start during our test +outf="$tmp/sed_tmp" +echo "s% Schedule =%# Schedule =%g" >${outf} +cp $scripts/bacula-dir.conf $tmp/1 +sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf + +change_jobname BackupClient1 $JobName + +start_test + +# Set small MaxVolSize so that we are sure many volumes are created during backup +$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumVolumeSize", "5M", "Device", "FileChgr1-Dev1")' + +# Run FD and DIR the usual way, SD has to be run with systemd +${bin}/bacula-ctl-fd start +if test $? -ne 0; then + print_debug "ERROR: Failed to start the FD!" + dstat=1 +fi +sudo systemctl start test-bacula-sd +if test $? -ne 0; then + print_debug "ERROR: Failed to start the SD!" + dstat=1 +fi +${bin}/bacula-ctl-dir start +if test $? -ne 0; then + print_debug "ERROR: Failed to start the DIR!" + dstat=1 +fi + +# No volume is created manually before running backup job so that Bacula has to create it by itself +cat <$tmp/bconcmds +@output /dev/null +messages +@$out $tmp/log1.out +run job=$JobName yes +wait +messages +@$out $tmp/log2.out +restore where=$tmp/bacula-restores select all done yes +wait +messages +quit +END_OF_DATA + +run_bconsole + +backup_res=`cat $tmp/log1.out| grep 'Termination:' | grep 'Backup OK' | wc -l` +if [ ${backup_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: JobId 1 did not succed, see ${tmp}/log2.out!" +fi + +# Check how many volumes were created +n_vols=`grep 'Volume name(s):' $tmp/log1.out | grep -o 'Vol-' | wc -l` + +# Check if all of the volumes created have the flag set +append_find=`lsattr ${tmp}/Vol-* -l | grep 'Append_Only' | wc -l` +if [ ${append_find} -ne ${n_vols} ]; then + estat=1 + print_debug "ERROR: Expected ${n_vols} volumes with the Append flag set, found ${append_find} instead!" +fi + +# Check if restore was ok +restore_res=`cat $tmp/log2.out| grep 'Termination:' | grep 'Restore OK' | wc -l` +if [ ${restore_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: Restoring job 1 did not succed, see ${tmp}/log3.out!" +fi + +sudo systemctl stop test-bacula-sd +${bin}/bacula-ctl-fd stop +${bin}/bacula-ctl-dir stop + +end_test diff --git a/regress/tests/volume-append-test b/regress/tests/volume-append-test new file mode 100755 index 000000000..9e627bdfd --- /dev/null +++ b/regress/tests/volume-append-test @@ -0,0 +1,165 @@ +#!/bin/sh +# +# Copyright (C) 2000-2021 Kern Sibbald +# License: BSD 2-Clause; see file LICENSE-FOSS +# +# Test if Volume used for backup is being set with the APPEND flag, +# so that it cannot be overwritten accidentally (while working fine +# with commands like 'relabel'). +# This test creates temporary bacula-sd.service file so that we can run SD +# as systemd service. +# +TestName="volume-append-test" +JobName=append + +. scripts/functions + +require_linux + +scripts/cleanup +scripts/copy-confs + +cleanup() +{ + #Stop the daemon if the test was interrupted in the middle of a run + sudo systemctl stop test-bacula-sd > /dev/null 2>&1 + #Disable the service + sudo systemctl disable test-bacula-sd + #Clear volume attributes if needed + sudo chattr -ia tmp/* +} + +trap 'cleanup' EXIT INT TERM + +# Create temporary bacula-sd.service file so that we can run SD as systemd service +scripts/create_sed +sed -f ${tmp}/sed_tmp ${cwd}/build/platforms/systemd/bacula-sd.service.in > ${tmp}/test-bacula-sd.service +sudo systemctl enable ${tmp}/test-bacula-sd.service + +# +# Zap out any schedule in default conf file so that +# it doesn't start during our test +# +outf="$tmp/sed_tmp" +echo "s% Schedule =%# Schedule =%g" >${outf} +cp $scripts/bacula-dir.conf $tmp/1 +sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf + +change_jobname BackupClient1 $JobName + +start_test + +# Run FD and DIR the usual way, SD has to be run with systemd +${bin}/bacula-ctl-fd start +if test $? -ne 0; then + print_debug "ERROR: Failed to start the FD!" + dstat=1 +fi +sudo systemctl start test-bacula-sd +if test $? -ne 0; then + print_debug "ERROR: Failed to start the SD!" + dstat=1 +fi +${bin}/bacula-ctl-dir start +if test $? -ne 0; then + print_debug "ERROR: Failed to start the DIR!" + dstat=1 +fi + +cat <$tmp/bconcmds +@output /dev/null +messages +@$out $tmp/log1.out +label volume=TestVolume001 storage=File1 pool=File slot=1 drive=0 +@$out $tmp/log2.out +run job=$JobName yes +wait +messages +@$out $tmp/log3.out +restore where=$tmp/bacula-restores select all done yes +wait +messages +quit +END_OF_DATA + +run_bconsole + +label_res=`cat $tmp/log1.out| grep '3000 OK label' | wc -l` +if [ ${label_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: Failed to label volume, see ${tmp}/log1.out!" +fi + +vol_res=`cat $tmp/log2.out| grep 'Volume name(s):' | grep 'TestVolume001' | wc -l` +if [ ${vol_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: Wrong volume used for backup, see ${tmp}/log2.out!" +fi + +backup_res=`cat $tmp/log2.out| grep 'Termination:' | grep 'Backup OK' | wc -l` +if [ ${backup_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: JobId 1 did not succed, see ${tmp}/log2.out!" +fi + +vol_res=`cat $tmp/log3.out| grep 'Ready to read from volume "TestVolume001"' | wc -l` +if [ ${vol_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: TestVolume001 not mentioned in restore log, see ${tmp}/log3.out!" +fi + +restore_res=`cat $tmp/log3.out| grep 'Termination:' | grep 'Restore OK' | wc -l` +if [ ${restore_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: Restoring job 1 did not succed, see ${tmp}/log3.out!" +fi + +# Check if Volume has the flag set +append_find=`lsattr ${tmp}/TestVolume001 -l | grep 'Append_Only' | wc -l` +if [ ${append_find} -ne 1 ]; then + estat=1 + print_debug "ERROR: TestVolume001 does not have the 'Append' flag set!" +fi + +# It should not be possible to overwrtie beginning of the Volume now +dd if=/dev/urandom of=$tmp/TestVolume001 bs=1M count=20 +if [ $? -ne 1 ]; then + estat=1 + print_debug "ERROR: Volume could be ovewritten from the beginning using dd!" +fi + +# As well as with some offset +dd if=/dev/urandom of=$tmp/TestVolume001 bs=1M count=20 skip=10 +if [ $? -ne 1 ]; then + estat=1 + print_debug "ERROR: Volume could be ovewritten from the 10M offset using dd!" +fi + +# Check if Bacula is still able to relabel Volume +cat <$tmp/bconcmds +@$out $tmp/log4.out +purge volume=TestVolume001 +relabel oldvolume=TestVolume001 volume=TestVolume002 slot=0 pool=Default storage=File1 drive=0 +list volumes +END_OF_DATA + +run_bconsole + +# Check if volume is relabeled and has correct state +label_res=`cat $tmp/log4.out| grep '3000 OK label' | grep 'TestVolume002' | wc -l` +if [ ${label_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: Failed to relabel volume, see ${tmp}/log4.out!" +fi + +new_vol=`cat $tmp/log4.out| grep 'TestVolume002' | grep 'Append' | wc -l` +if [ ${new_vol} -ne 1 ]; then + estat=1 + print_debug "ERROR: Failed to relabel volume, see ${tmp}/log3.out" +fi + +sudo systemctl stop test-bacula-sd +${bin}/bacula-ctl-fd stop +${bin}/bacula-ctl-dir stop + +end_test diff --git a/regress/tests/volume-immutable-test b/regress/tests/volume-immutable-test new file mode 100755 index 000000000..bf1787413 --- /dev/null +++ b/regress/tests/volume-immutable-test @@ -0,0 +1,145 @@ +#!/bin/sh +# +# Copyright (C) 2000-2021 Kern Sibbald +# License: BSD 2-Clause; see file LICENSE-FOSS +# +# Test if Volumes created automatically by bacula during backup +# are set with the APPEND flag, so that it cannot be overwritten accidentally. +# Check if Full volumes have the IMMUTABLE flag so that it cannot be modified. +# Check if volume can be relabeled after protection time expiration. +# This test creates temporary bacula-sd.service file so that we can run SD +# as systemd service. +# +TestName="volume-append-many-vols-test" +JobName=append + +. scripts/functions + +require_linux + +scripts/cleanup +scripts/copy-confs + +cleanup() +{ + #Stop the daemon if the test was interrupted in the middle of a run + sudo systemctl stop test-bacula-sd > /dev/null 2>&1 + #Disable the service + sudo systemctl disable test-bacula-sd + #Clear volume attributes if needed + sudo chattr -ia tmp/* +} + +trap 'cleanup' EXIT INT TERM + +# Create temporary bacula-sd.service file so that we can run SD as systemd service +scripts/create_sed +sed -f ${tmp}/sed_tmp ${cwd}/build/platforms/systemd/bacula-sd.service.in > ${tmp}/test-bacula-sd.service +sudo systemctl enable ${tmp}/test-bacula-sd.service + +# Zap out any schedule in default conf file so that +# it doesn't start during our test +outf="$tmp/sed_tmp" +echo "s% Schedule =%# Schedule =%g" >${outf} +cp $scripts/bacula-dir.conf $tmp/1 +sed -f ${outf} $tmp/1 >$scripts/bacula-dir.conf + +change_jobname BackupClient1 $JobName + +start_test + +# Set small MaxVolSize so that many volumes are created during backup +$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumVolumeSize", "50M", "Device", "FileChgr1-Dev1")' +$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MaximumVolumeSize", "50M", "Device", "FileChgr1-Dev2")' + +# Set some protection directives +$bperl -e 'add_attribute("$conf/bacula-sd.conf", "ProtectVolumes", "yes", "Device", "FileChgr1-Dev1")' +$bperl -e 'add_attribute("$conf/bacula-sd.conf", "ProtectVolumes", "yes", "Device", "FileChgr1-Dev2")' +$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MinimumVolumeProtectionTime", "10seconds", "Device", "FileChgr1-Dev1")' +$bperl -e 'add_attribute("$conf/bacula-sd.conf", "MinimumVolumeProtectionTime", "10seconds", "Device", "FileChgr1-Dev2")' + +# Run FD and DIR the usual way, SD has to be run with systemd +${bin}/bacula-ctl-fd start +if test $? -ne 0; then + print_debug "ERROR: Failed to start the FD!" + dstat=1 +fi +sudo systemctl start test-bacula-sd +if test $? -ne 0; then + print_debug "ERROR: Failed to start the SD!" + dstat=1 +fi +${bin}/bacula-ctl-dir start +if test $? -ne 0; then + print_debug "ERROR: Failed to start the DIR!" + dstat=1 +fi + +# No volume is created manually before running backup job so that Bacula has to create it by itself +cat <$tmp/bconcmds +@output /dev/null +messages +@$out $tmp/log1.out +run job=$JobName yes +wait +messages +quit +END_OF_DATA + +run_bconsole + +backup_res=`cat $tmp/log1.out| grep 'Termination:' | grep 'Backup OK' | wc -l` +if [ ${backup_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: JobId 1 did not succed, see ${tmp}/log2.out!" +fi + +# Check how many volumes were created +n_vols=`grep 'Volume name(s):' $tmp/log1.out | grep -o 'Vol-' | wc -l` + +# Check if all of the volumes created have the flag set +append_find=`lsattr ${tmp}/Vol-* -l | grep 'Append_Only' | wc -l` +if [ ${append_find} -ne ${n_vols} ]; then + estat=1 + print_debug "ERROR: Expected ${n_vols} volumes with the Append flag set, found ${append_find} instead!" +fi + +# We expect n_vols-1 volumes to be marked as Immutable (last one still has some space on it) +immutable_find=`lsattr ${tmp}/Vol-* -l | grep 'Immutable' | wc -l` +immutable_expected=$((n_vols-1)) +if [ ${immutable_find} -ne $immutable_expected ]; then + estat=1 + print_debug "ERROR: Expected ${immutable_expected} volumes with the Immputable flag set, found ${immutable_find} instead!" +fi + +cat <$tmp/bconcmds +@$out $tmp/log2.out +purge volume=Vol-0001 +relabel oldvolume=Vol-0001 volume=RelabeledVol-0001 slot=0 pool=Default storage=File1 drive=0 +@$out $tmp/log3.out +@sleep 20 +relabel oldvolume=Vol-0001 volume=RelabeledVol-0001 slot=0 pool=Default storage=File1 drive=0 +quit +END_OF_DATA + +run_bconsole + +# Check if volume has not been relabeled before expiration time +label_res=`cat $tmp/log2.out| grep "Immutable flag cannot be cleared for volume: Vol-0001, because Minimum Volume Protection Time hasn't expired yet" | wc -l` +if [ ${label_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: Failed to relabel volume, see ${tmp}/log2.out!" +fi + +# Check if volume is relabeled and has correct state after waiting some more time +label_res=`cat $tmp/log3.out| grep '3000 OK label' | grep 'RelabeledVol-0001' | wc -l` +if [ ${label_res} -ne 1 ]; then + estat=1 + print_debug "ERROR: Failed to relabel volume, see ${tmp}/log3.out!" +fi + +sudo systemctl stop test-bacula-sd +${bin}/bacula-ctl-fd stop +${bin}/bacula-ctl-dir stop + +end_test