2222# Shared between s3_backup_test.sh, s3_backup_bulkdump_bulkload.sh, dir_backup_test.sh, etc.
2323# These functions work with both S3/blobstore and file-based backup testing
2424
25+ # Source shared test utilities (output_contains, output_matches, etc.)
26+ _BACKUP_COMMON_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
27+ if [[ -f " ${_BACKUP_COMMON_DIR} /../../fdbclient/tests/tests_common.sh" ]]; then
28+ source " ${_BACKUP_COMMON_DIR} /../../fdbclient/tests/tests_common.sh"
29+ fi
30+
2531# Helper function to add base arguments (cluster file and logging)
2632# Uses bash nameref (requires bash 4.3+) to modify the array in place
2733# $1 name of the array variable to modify (passed by name, not value)
@@ -182,12 +188,12 @@ function run_backup {
182188 set -e
183189
184190 # Check if backup is restorable (differential state) or completed
185- if echo " ${status_output} " | grep -q " is restorable" ; then
191+ if output_contains " ${status_output} " " is restorable" ; then
186192 log " Backup is now restorable after ${elapsed} s"
187193 break
188194 fi
189195
190- if echo " ${status_output} " | grep -q " completed" ; then
196+ if output_contains " ${status_output} " " completed" ; then
191197 log " Backup completed after ${elapsed} s"
192198 break
193199 fi
@@ -196,17 +202,17 @@ function run_backup {
196202 if [[ $(( elapsed % 30 )) -eq 0 ]]; then
197203 log " Still waiting for backup to become restorable (${elapsed} s elapsed)..."
198204 # Show current state for debugging
199- if echo " ${status_output} " | grep -q " is restorable" ; then
205+ if output_contains " ${status_output} " " is restorable" ; then
200206 log " Status: backup is restorable (should have exited loop)"
201- elif echo " ${status_output} " | grep -q " in progress to" ; then
207+ elif output_contains " ${status_output} " " in progress to" ; then
202208 log " Status: backup running, waiting for snapshot to complete"
203- elif echo " ${status_output} " | grep -q " just started" ; then
209+ elif output_contains " ${status_output} " " just started" ; then
204210 log " Status: backup submitted, tasks starting up"
205211 fi
206212 # Check snapshot mode for debugging
207- if echo " ${status_output} " | grep -q " Snapshot Mode: bulkdump" ; then
213+ if output_contains " ${status_output} " " Snapshot Mode: bulkdump" ; then
208214 log " Snapshot Mode: bulkdump (using BulkDump for snapshots)"
209- elif echo " ${status_output} " | grep -q " Snapshot Mode: both" ; then
215+ elif output_contains " ${status_output} " " Snapshot Mode: both" ; then
210216 log " Snapshot Mode: both (generating both formats)"
211217 fi
212218 fi
@@ -238,7 +244,7 @@ function run_backup {
238244 set -e
239245
240246 # Check if BulkDump snapshot exists (look for bulkDumpJobId in describe output)
241- if echo " ${snapshot_list} " | grep -q " bulkDumpJobId\|,bulk" ; then
247+ if output_matches " ${snapshot_list} " " bulkDumpJobId\|,bulk" ; then
242248 log " BulkDump snapshot found after ${bulkdump_elapsed} s"
243249 break
244250 fi
@@ -255,7 +261,7 @@ function run_backup {
255261 fi
256262
257263 # Check if backup already completed (no need to discontinue)
258- if echo " ${status_output} " | grep -q " completed" ; then
264+ if output_contains " ${status_output} " " completed" ; then
259265 log " Backup already completed - no need to discontinue"
260266 return 0
261267 fi
@@ -268,7 +274,7 @@ function run_backup {
268274 set -e
269275
270276 if [[ $stop_exit_code -ne 0 ]]; then
271- if echo " ${stop_output} " | grep -q " already discontinued\|not running\|unneeded" ; then
277+ if output_matches " ${stop_output} " " already discontinued\|not running\|unneeded" ; then
272278 log " Backup already completed and finalized - this is success!"
273279 else
274280 err " Failed to stop backup: ${stop_output} "
@@ -334,13 +340,13 @@ function run_restore {
334340 # Check if restore completed
335341 # Status output contains "State: completed" or "Phase: Complete" when done
336342 # Also check "No restore" for when restore tag doesn't exist (completed and cleaned up)
337- if echo " ${status_output} " | grep -qi " State:.*completed\|Phase:.*Complete\|No restore" ; then
343+ if output_matches_i " ${status_output} " " State:.*completed\|Phase:.*Complete\|No restore" ; then
338344 log " Restore completed after ${elapsed} s"
339345 return 0
340346 fi
341347
342348 # Check if restore failed (be specific - "LastError: None" contains "Error" so avoid false positives)
343- if echo " ${status_output} " | grep -qi " State:.*aborted" ; then
349+ if output_matches_i " ${status_output} " " State:.*aborted" ; then
344350 err " Restore aborted after ${elapsed} s"
345351 log " Status output:"
346352 echo " ${status_output} "
@@ -359,7 +365,7 @@ function run_restore {
359365 if [[ $(( elapsed % 30 )) -eq 0 ]]; then
360366 log " Still waiting for restore to complete (${elapsed} s elapsed)..."
361367 # Show phase info for debugging
362- if echo " ${status_output} " | grep -qi " Phase:" ; then
368+ if output_matches_i " ${status_output} " " Phase:" ; then
363369 phase_info=$( echo " ${status_output} " | grep -i " Phase:" | head -1)
364370 log " ${phase_info} "
365371 fi
@@ -496,11 +502,11 @@ function run_restore_wait {
496502 status_output=$( " ${local_build_dir} " /bin/fdbrestore status -t " ${local_tag} " --dest-cluster-file " ${local_scratch_dir} /loopback_cluster/fdb.cluster" --log --logdir=" ${local_scratch_dir} " 2>&1 )
497503 set -e
498504
499- if echo " ${status_output} " | grep -qi " State:.*completed\|Phase:.*Complete\|No restore" ; then
505+ if output_matches_i " ${status_output} " " State:.*completed\|Phase:.*Complete\|No restore" ; then
500506 return 0
501507 fi
502508
503- if echo " ${status_output} " | grep -qi " State:.*aborted" ; then
509+ if output_matches_i " ${status_output} " " State:.*aborted" ; then
504510 return 1
505511 fi
506512
0 commit comments