1#!/bin/sh
2#
3# Run a simple backup
4#   prune file records, then restore only README files.
5#
6TestName="fileregexp-test"
7JobName=backup
8. scripts/functions
9
10scripts/cleanup
11scripts/copy-confs
12
13#
14# Zap out any schedule in default conf file so that
15#  it doesn't start during our test
16#
17outf="${tmp}/sed_tmp"
18echo "s%  Schedule =%# Schedule =%g" >${outf}
19cp ${conf}/bareos-dir.conf ${tmp}/1
20sed -f ${outf} ${tmp}/1 >${conf}/bareos-dir.conf
21
22$bperl -e "add_attribute('${conf}/bareos-dir.conf', 'File Retention', '2', 'Client')"
23
24change_jobname BackupClient1FileList $JobName
25
26# Directory to backup.
27# This directory will be created by setup_data().
28BackupDirectory="${tmp}/data"
29
30# Use a tgz to setup data to be backuped.
31# Data will be placed at "${tmp}/data/".
32setup_data data/small.tgz
33
34# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
35echo "${BackupDirectory}" >${tmp}/file-list
36
37mkdir -p ${BackupDirectory}/test/
38echo "test" > ${BackupDirectory}/test/t1.txt
39echo "test" > ${BackupDirectory}/test/t2.txt
40echo "test" > ${BackupDirectory}/test/t3.txt
41
42start_test
43
44cat <<END_OF_DATA >${tmp}/bconcmds
45@$out /dev/null
46messages
47@$out ${tmp}/log1.out
48label volume=TestVolume001 storage=File pool=Full
49run job=$JobName yes
50wait
51messages
52@sleep 5
53prune files yes
54quit
55END_OF_DATA
56
57run_bareos
58
59# to make incremental backup
60echo "test" > ${BackupDirectory}/inc1.dat
61
62cat <<END_OF_DATA >${tmp}/bconcmds
63run job=$JobName yes
64wait
65messages
66@#
67@# now do a restore
68@#
69@$out ${tmp}/log2.out
70restore where=${tmp}/bareos-restores
715
72no
73.*\.txt
74yes
75wait
76messages
77END_OF_DATA
78
79run_bconsole
80
81check_for_zombie_jobs storage=File
82stop_bareos
83
84#
85# The above restore should have restored some directories, but only
86# files that have *.txt in their name.  There should in fact, be
87# no other files restored COUNT_OTHER==0 and more then 0 files restored.
88#
89COUNT_OTHER=`find ${tmp}/bareos-restores -type f | grep -v .txt$ | wc -l`
90COUNT_README=`find ${tmp}/bareos-restores -type f | grep .txt$ | wc -l`
91
92if [ $COUNT_OTHER -gt 0 -o $COUNT_README -lt 1 ]; then
93    print_debug "Found non matching files"
94    print_debug "Count_other=$COUNT_OTHER count_readme=$COUNT_README"
95    print_debug `find ${tmp}/bareos-restores -type f | grep -v README`
96    rstat=2
97fi
98
99#check_two_logs         # don't work because of "warning file count mismatch"
100grep "Backup OK" ${tmp}/log1.out > /dev/null
101if [ $? -ne 0 ]; then
102    print_debug "Found error in backup"
103    bstat=2
104fi
105
106end_test
107