]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport regress/tests/director-autoprune-test
authorEric Bollengier <eric@baculasystems.com>
Wed, 2 Sep 2020 13:22:14 +0000 (15:22 +0200)
committerEric Bollengier <eric@baculasystems.com>
Tue, 1 Mar 2022 14:36:18 +0000 (15:36 +0100)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Tue Jul 21 10:28:13 2020 +0200

    regress: Add copyright to regress scripts

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Jan 24 10:41:34 2019 +0100

    regress: Check status dir and restore on director-autoprune-test

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Sat Dec 22 17:16:01 2018 +0100

    regress: Enhance director-autoprune-test to test status dir as well

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Dec 21 10:11:49 2018 +0100

    regress: Add test for the Director:Autoprune feature

regress/tests/director-autoprune-test [new file with mode: 0755]

diff --git a/regress/tests/director-autoprune-test b/regress/tests/director-autoprune-test
new file mode 100755 (executable)
index 0000000..8598222
--- /dev/null
@@ -0,0 +1,168 @@
+#!/bin/sh
+#
+# Copyright (C) 2000-2020 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+# This script will test prune algo 
+#
+. scripts/functions
+
+TestName="director-autoprune-test"
+JobName=NightlySave
+
+scripts/cleanup
+scripts/copy-test-confs
+
+setup_shstore # simulate shared storage if enabled
+
+start_test
+
+echo $PWD/build/po > tmp/file-list
+# We want to have pruning only when doing prune command
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "AutoPrune", "No", "Director")'
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "Job Retention", "1s", "Client")'
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "File Retention", "1s", "Client")'
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "Schedule", "WeeklyCycle", "Job")'
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "MaximumVolumeJobs", "1", "Pool")'
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "LabelFormat", "Vol", "Pool")'
+
+cat <<EOF > ${cwd}/tmp/bconcmds
+@output /dev/null
+messages
+@$out $tmp/log1.out
+run job=$JobName level=full yes
+wait
+messages
+@exec "touch $cwd/build/po/fr.po"
+run job=$JobName level=incremental yes
+wait
+messages
+@exec "touch $cwd/build/po/de.po"
+run job=$JobName level=incremental yes
+wait
+messages
+@sleep 2
+@$out $tmp/log3.out
+@################################################################
+@# Should not prune anything
+list jobs
+prune jobs yes
+list jobs
+@$out $tmp/log4.out
+@################################################################
+@# Should prune the two firsts incrementals
+run job=$JobName level=differential yes
+wait
+messages
+@exec "touch $cwd/build/po/es.po"
+run job=$JobName level=incremental yes
+wait
+messages
+status dir
+@sleep 2
+list jobs
+prune jobs yes
+list jobs
+@$out $tmp/log5.out
+@################################################################
+@# Should prune the first Full+Diff job
+run job=$JobName level=full yes
+wait
+messages
+@sleep 2
+list jobs
+prune jobs yes
+list jobs
+@$out $tmp/log6.out
+@################################################################
+run job=$JobName level=incremental yes
+wait
+messages
+@$out $tmp/log2.out
+restore where=${cwd}/tmp/bacula-restores select all storage=File done
+yes
+wait
+messages
+@sleep 2
+@$out $tmp/log6.out
+@################################################################
+@# Should not prune anything
+list jobs
+status dir
+list jobs
+@$out $tmp/log7.out
+@################################################################
+@# Should prune the restore job and the last incremental job (jobfiles=0)
+list jobs
+prune jobs yes
+list jobs
+quit
+quit
+EOF
+
+run_bacula
+
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "AutoPrune", "Yes", "Director")'
+
+cat <<EOF > ${cwd}/tmp/bconcmds
+@output /dev/null
+messages
+@$out $tmp/alog7.out
+reload
+run job=$JobName level=incremental yes
+wait
+messages
+EOF
+
+run_bconsole
+
+stop_bacula
+
+check_two_logs
+
+estat=0
+
+grep -i 'auto prune' $tmp/log*.out > /dev/null
+if [ $? = 0 ]; then
+    print_debug "ERROR: Should not find Autoprune messages in job log"
+    estat=1
+fi
+
+grep -i 'auto prune' $tmp/alog7.out > /dev/null
+if [ $? != 0 ]; then
+    print_debug "ERROR: Should find Autoprune messages in job log $tmp/alog7.log"
+    estat=1
+fi
+
+###############################################################################
+# Now we will verify that the pruning code is working as expected.  Each time,
+# we run 'list jobs', 'prune', 'list jobs'. check_prune_list ensures that jobids
+# in argument are present in the first 'list jobs', the 'prune' command deletes
+# them (same number), and checks that the last 'list jobs' doesn't contain them
+# anymore. See scripts/functions.pm for details.
+
+# nothing should be pruned
+$bperl -e "check_prune_list('$tmp/log3.out')"
+estat=$(($estat + $?))
+
+# jobids 2 and 3 should be pruned
+# (F I I D) -> (F D)
+$bperl -e "check_prune_list('$tmp/log4.out',2,3)"
+estat=$(($estat + $?))
+
+# (F D I F) -> (F)
+$bperl -e "check_prune_list('$tmp/log5.out',1,4,5)"
+estat=$(($estat + $?))
+
+# (F I R) -> (F I R)     -- Incremental have 0 file
+$bperl -e "check_prune_list('$tmp/log6.out')"
+estat=$(($estat + $?))
+
+# (F I R) -> (F)     -- Incremental have 0 file
+$bperl -e "check_prune_list('$tmp/log7.out',7,8)"
+estat=$(($estat + $?))
+
+$rscripts/diff.pl -s $cwd/build/po -d $tmp/bacula-restores/$cwd/build/po
+rstat=$(($rstat + $?))
+
+end_test