]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport regress/tests/snapshot-zfs-test
authorEric Bollengier <eric@baculasystems.com>
Wed, 2 Sep 2020 13:34:57 +0000 (15:34 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:55 +0000 (09:02 +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:   Fri Mar 20 09:22:03 2015 +0100

    regress: Tweak snapshot tests for new trace output

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Fri Feb 20 17:11:14 2015 +0100

    snapshot: More work on LVM backend and on list/sync commands

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Wed Feb 18 10:21:46 2015 +0100

    regress: use bsnapshot.conf in regress tests

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Feb 5 09:42:01 2015 +0100

    Add Snapshot Engine to bacula core

            Rename jcr->VSS to jcr->Snapshot and use the same variable on Linux/Windows
            Pass snapshot retention to the FD
            Add SnapshotRetention to client and job resource
            Add documentation about snapshot backend
            regress: Add snapshot script for lvm backend
            Use retry in lvm unmount procedure
            Read config file from sysconfigdir
            Load bsnapshot.cfg by default and configure bsnapshot using exepath
            Add config file to specify lvm snapshot parameters
            Control LVM free space for snapshot
            Implement OT_PINT64 in output writer, should display job speed api2 mode status command
            regress: Add test to test snapshot bconsole commands
            regress: Add test for zfs snapshot
            implement zfs driver (linux zfs driver cannot mount snapshots)
            regress: Add regress script for snapshots
            Include automatically subvolumes with onefs=no
            Handle ff->link in strip snapshot path
            Scan for subvolumes not listed in mtab
            Snapshots can be created/deleted from the catalog
            Implement path translation between snapshot
            Add JobId to Snapshot table
            Add code to execute snapshot script on the FD side
            Add more Director snapshots command
            Implement CatReq interface for Snapshots
            Implement DB snapshot functions
            the delete snapshot is now connecting to the FD, and the
            FD is calling the snapshot script with the delete argument
            Allow to specify env variable in run_command_full_output() and open_bpipe()
            Modify cmd_parser to not look for plugin name with use_name option
            Add ARG_LIST to generate nice arg1=arg2 output from db_list function
            Add tag DT_SNAPSHOT
            Add JobId in the list snapshot output
            Add list snapshot command
            Add JobId to snapshot table

regress/tests/snapshot-zfs-test [new file with mode: 0755]

diff --git a/regress/tests/snapshot-zfs-test b/regress/tests/snapshot-zfs-test
new file mode 100755 (executable)
index 0000000..0236e30
--- /dev/null
@@ -0,0 +1,215 @@
+#!/bin/bash
+#
+# Copyright (C) 2000-2020 Kern Sibbald
+# License: BSD 2-Clause; see file LICENSE-FOSS
+#
+# create zfs volume and play with snapshots
+#
+TestName="snapshot-zfs-test"
+JobName=Incremental
+. scripts/functions
+
+${rscripts}/cleanup
+${rscripts}/copy-test-confs
+
+USE_SUDO=${USE_SUDO:-sudo}
+
+if [ "$USE_SUDO" = sudo ]; then
+    echo sudo=yes > $conf/bsnapshot.conf
+fi
+
+fdir=$cwd/zfs
+ZFS="$USE_SUDO zfs"
+ZPOOL="$USE_SUDO zpool"
+
+cleanup()
+{
+    $ZFS unmount bpool/test/subvol
+    $ZFS unmount bpool/test
+
+    $ZFS destroy bpool/test/subvol
+    $ZFS destroy bpool/test
+}
+
+if [ ! -f $fdir.img ]; then
+    dd of=$fdir.img if=/dev/zero seek=600 bs=1MB count=1
+    $ZPOOL create bpool $fdir.img
+fi
+
+mkdir -p $fdir
+$ZFS create bpool/test
+$ZFS set mountpoint=$fdir bpool/test
+$ZFS mount bpool/test
+
+trap EXIT cleanup
+
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Unable to mount zfs image"
+    exit 1
+fi
+
+GID=`id -g`
+$USE_SUDO chown $USER:$GID $fdir
+
+echo "$fdir" >${tmp}/file-list
+cp -p ${src}/src/dird/*.c $fdir
+
+make -C $cwd/build/src/tools install-bsnapshot
+
+$bperl -e 'add_attribute("$conf/bacula-dir.conf", "Enable Snapshot", "yes", "FileSet")'
+
+change_jobname CompressedTest $JobName
+start_test
+
+cat <<END_OF_DATA >${tmp}/bconcmds
+@output /dev/null
+messages
+@$out ${tmp}/log1.out
+setdebug level=20 tags=snapshot fd trace=1
+label storage=File volume=TestVolume001
+run job=$JobName yes
+status client
+wait
+messages
+@output ${tmp}/list1
+list files jobid=1
+END_OF_DATA
+
+run_bacula
+check_for_zombie_jobs storage=File
+
+cat <<END_OF_DATA >${tmp}/bconcmds
+@# 
+@# now do a restore
+@#
+@$out ${tmp}/log2.out
+restore where=${tmp}/bacula-restores storage=File select all yes done
+wait
+status client
+messages
+quit
+END_OF_DATA
+
+run_bconsole
+
+$SUDO zfs set snapdir=hidden bpool/test
+$rscripts/diff.pl -s $fdir -d $tmp/bacula-restores/$fdir
+
+grep .zfs/snapshots $tmp/list1
+if [ $? -eq 0 ]; then
+    print_debug "ERROR: Should not find .zfs/snapshots directory"
+    estat=1
+fi
+
+f=`ls $working/*.trace`
+cp $f $working/job1.trace
+cp /dev/null $f
+
+grep -E "Adding $fdir dev=[0-9]+ snap.=1 to the mount list" $working/job1.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find $fdir in the FD $working/job1.trace file"
+    estat=1
+fi
+
+grep "$fdir snapshot support status=1" $working/job1.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find $fdir snapshot support in the FD $working/job1.trace file"
+    estat=1
+fi
+
+grep "Create Snapshot of $fdir $JobName" $working/job1.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find snapshot creation in FD $working/job1.trace file"
+    estat=1
+fi
+
+grep "fname=$fdir/.snapshots/Incremental.*/admin.c stripped=$fdir/admin.c link=$fdir/admin.c" $working/job1.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should path convertion in FD $working/job1.trace trace file"
+    estat=1
+fi
+
+$ZFS create $fdir/subvol
+$USE_SUDO chown $USER:$GID $fdir/subvol
+cp $cwd/build/README $fdir/subvol
+
+cat <<END_OF_DATA >${tmp}/bconcmds
+@$out ${tmp}/log3.out
+setdebug level=20 tags=snapshot fd trace=1
+run level=full job=$JobName yes
+wait
+messages
+@output ${tmp}/list3
+list files jobid=3
+@# 
+@# now do a restore
+@#
+@$out ${tmp}/log4.out
+restore where=${tmp}/bacula-restores4 storage=File select all yes done
+wait
+status client
+messages
+quit
+END_OF_DATA
+
+run_bconsole
+
+cp $f $working/job3.trace
+
+grep -E "Adding $fdir dev=[0-9]+ snap.=1 to the mount list" $working/job3.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find $fdir in the FD $working/job3.trace file"
+    estat=1
+fi
+
+grep "$fdir snapshot support status=1" $working/job3.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find $fdir snapshot support in the FD $working/job3.trace file"
+    estat=1
+fi
+
+grep "Create Snapshot of $fdir $JobName" $working/job3.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find snapshot creation in FD $working/job3.trace file"
+    estat=1
+fi
+
+grep "fname=$fdir/.zfs/snapshots/Incremental.*/admin.c stripped=$fdir/admin.c link=$fdir/admin.c" $working/job3.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should path convertion in FD $working/job3.trace trace file"
+    estat=1
+fi
+
+grep -E "Adding $fdir/subvol dev=[0-9]+ snap.=1 to the mount list" $working/job3.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find $fdir/subvol in the FD $working/job3.trace file"
+    estat=1
+fi
+
+grep "$fdir/subvol snapshot support status=1" $working/job3.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find $fdir snapshot support in the FD $working/job3.trace file"
+    estat=1
+fi
+
+grep "Create Snapshot of $fdir/subvol $JobName" $working/job3.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should find snapshot creation in FD $working/job3.trace file"
+    estat=1
+fi
+
+grep "fname=$fdir/subvol/.zfs/snapshots/Incremental.*/README stripped=$fdir/subvol/README link=$fdir/subvol/README" $working/job3.trace > /dev/null
+if [ $? -ne 0 ]; then
+    print_debug "ERROR: Should path convertion in FD $working/job3.trace trace file"
+    estat=1
+fi
+
+$USER_SUDO zfs set snapdir=hidden bpool/test/subvol
+$rscripts/diff.pl -s $fdir -d $tmp/bacula-restores4/$fdir
+
+
+stop_bacula
+
+check_two_logs
+
+end_test