-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_zfs_backup_manager.sh
executable file
·762 lines (583 loc) · 27.3 KB
/
test_zfs_backup_manager.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
#!/bin/bash
# shellcheck disable=SC2034
# ZFS Backup Manager Test Script
# Version 0.0.2
# Copyright 2017-2018 Romaco Canada, Mark Furneaux
# An ssh key to the local root user is needed for the remote tests to pass.
SCRIPT=$(realpath "$0")
SCRIPT_PATH=$(dirname "$SCRIPT")
# Test config. Shouldn't conflict with any real systems...
SOURCE_POOL_FILE="testsource.img"
SOURCE2_POOL_FILE="testsource2.img"
DEST_POOL_FILE="testdest.img"
SOURCE_POOL="testsource_138975"
SOURCE_POOL_2="testsource2_138975"
DEST_POOL="testdest_138975"
ZFS_MODE_PROPERTY="furneaux:testautobackup"
# Lock file the script uses
LOCK_FILE="/var/run/zfs-backup-manager.lock"
# Error codes from the script
SUCCESS=0
LOCK_FILE_PRESENT=1
NO_DATASETS=2
CONFIG_INVALID=3
ROOT_INVALID=4
MODE_INVALID=5
INTERNAL_FAULT=6
NEST_NAME_MISSING=7
NO_PATTERN_MATCH=8
MISSING_SNAPSHOT=9
COMM_ERROR=10
TIME_SANITY_FAIL=11
SEND_RECV_FAIL=12
# Test tallies
TOTAL_TESTS=0
PASS_TESTS=0
FAIL_TESTS=0
FAIL_FAST=0
log () {
echo "[TEST] $1"
}
check_result () {
((TOTAL_TESTS++)) || true
EXPECT=$1
CODE=$2
if [ "$EXPECT" -eq "$CODE" ]; then
((PASS_TESTS++)) || true
log "~~~PASS~~~"
else
((FAIL_TESTS++)) || true
log "~~~FAIL~~~"
if [ $FAIL_FAST -eq 1 ]; then
log "Dumping current config..."
zfs list
general_test_teardown
exit 100
fi
fi
}
general_test_setup () {
log "Test Setup..."
truncate -s 100M "$SOURCE_POOL_FILE"
truncate -s 100M "$SOURCE2_POOL_FILE"
truncate -s 100M "$DEST_POOL_FILE"
zpool create $SOURCE_POOL "$SCRIPT_PATH/$SOURCE_POOL_FILE"
zpool create $SOURCE_POOL_2 "$SCRIPT_PATH/$SOURCE2_POOL_FILE"
zpool create $DEST_POOL "$SCRIPT_PATH/$DEST_POOL_FILE"
zfs create $SOURCE_POOL/a
zfs create $SOURCE_POOL_2/b
zfs create $DEST_POOL/n
zfs create $DEST_POOL/m
zfs snapshot -r $SOURCE_POOL@zfs-auto-snap_daily1
zfs snapshot $SOURCE_POOL_2/b@zfs-auto-snap_daily1
}
path_setup () {
zfs set $ZFS_MODE_PROPERTY=path $SOURCE_POOL/a
zfs send -R $SOURCE_POOL/a@zfs-auto-snap_daily1 | sudo zfs recv -dF $DEST_POOL
}
nested_setup () {
zfs set $ZFS_MODE_PROPERTY=nested $SOURCE_POOL_2/b
zfs set furneaux:backupnestname=m $SOURCE_POOL_2/b
zfs send $SOURCE_POOL_2/b@zfs-auto-snap_daily1 | sudo zfs recv $DEST_POOL/m/b
}
root_setup () {
zfs set $ZFS_MODE_PROPERTY=root $SOURCE_POOL
zfs set furneaux:backupnestname=n $SOURCE_POOL
zfs send -R $SOURCE_POOL@zfs-auto-snap_daily1 | sudo zfs recv $DEST_POOL/n/$SOURCE_POOL
}
general_test_teardown () {
log "Test Teardown..."
zpool destroy $SOURCE_POOL
zpool destroy $SOURCE_POOL_2
zpool destroy $DEST_POOL
rm $SOURCE_POOL_FILE
rm $SOURCE2_POOL_FILE
rm $DEST_POOL_FILE
if [ -e $LOCK_FILE ]; then
rm $LOCK_FILE
fi
}
create_snapshots () {
log "Generating New Snapshots..."
# generate some incompressible data to send
dd if=/dev/urandom of=/$SOURCE_POOL/testfile bs=1M count=30 > /dev/random 2>&1
zfs snapshot -r $SOURCE_POOL@zfs-auto-snap_daily3
zfs snapshot -r $SOURCE_POOL_2@zfs-auto-snap_daily3
sleep 1
zfs snapshot -r $SOURCE_POOL@zfs-auto-snap_daily4
zfs snapshot -r $SOURCE_POOL_2@zfs-auto-snap_daily4
sleep 1
zfs snapshot -r $SOURCE_POOL@zfs-auto-snap_daily5
zfs snapshot -r $SOURCE_POOL_2@zfs-auto-snap_daily5
sleep 1
zfs snapshot -r $SOURCE_POOL@zfs-auto-snap_daily6
zfs snapshot -r $SOURCE_POOL_2@zfs-auto-snap_daily6
sleep 1
zfs snapshot -r $SOURCE_POOL@zfs-auto-snap_daily7
zfs snapshot -r $SOURCE_POOL_2@zfs-auto-snap_daily7
}
test_local () {
log "=================================================="
log "Test successful local backup..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $SUCCESS $?
general_test_teardown
}
test_additional_options () {
log "=================================================="
log "Test additional options..."
log "=================================================="
general_test_setup
zfs set furneaux:backupopts="-o com.sun:auto-snapshot=false" $SOURCE_POOL/a
create_snapshots
path_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh --zfs-options-property "furneaux:backupopts"
check_result $SUCCESS $?
general_test_teardown
}
test_simulation () {
log "=================================================="
log "Test simulation..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
# create a situation which looks correct but will fail if attempted
zfs destroy $DEST_POOL/a@zfs-auto-snap_daily1
zfs snapshot $DEST_POOL/a@zfs-auto-snap_daily1
sleep 1
zfs snapshot $SOURCE_POOL/a@zfs-auto-snap_daily9
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --simulate --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $SUCCESS $?
general_test_teardown
}
test_missing_nest_name_property () {
log "=================================================="
log "Test missing nest name property..."
log "=================================================="
general_test_setup
create_snapshots
nested_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh --nest-name-property ""
check_result $CONFIG_INVALID $?
general_test_teardown
}
test_chain_backup_local () {
log "=================================================="
log "Test chain backup local..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
nested_setup
root_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh --nest-name-property "furneaux:backupnestname" --ssh-options ""
check_result $SUCCESS $?
general_test_teardown
}
test_chain_backup_ssh () {
log "=================================================="
log "Test chain backup ssh..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
nested_setup
root_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --remote-mode ssh --remote-user "root" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --nest-name-property "furneaux:backupnestname" --ssh-options ""
check_result $SUCCESS $?
general_test_teardown
}
test_chain_backup_mbuffer () {
log "=================================================="
log "Test chain backup mbuffer..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
nested_setup
root_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --remote-mode mbuffer --remote-user "root" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --nest-name-property "furneaux:backupnestname"
check_result $SUCCESS $?
general_test_teardown
}
test_no_pattern_match () {
log "=================================================="
log "Test no pattern match..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "no_match_pattern" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $NO_PATTERN_MATCH $?
general_test_teardown
}
test_no_pattern_match_remote () {
log "=================================================="
log "Test no pattern match on remote..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
zfs destroy $DEST_POOL/a@zfs-auto-snap_daily1
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $NO_PATTERN_MATCH $?
general_test_teardown
}
test_remote_ahead_of_local () {
log "=================================================="
log "Test remote ahead of local..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
# create a snapshot on the destionation which does not exist on the source
zfs snapshot $DEST_POOL/a@zfs-auto-snap_daily9
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $MISSING_SNAPSHOT $?
general_test_teardown
}
test_time_sanity_local () {
log "=================================================="
log "Test time sanity local..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
# create a snapshot with the same name as one on the source, but newer
sleep 1
zfs snapshot $DEST_POOL/a@zfs-auto-snap_daily6
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $TIME_SANITY_FAIL $?
general_test_teardown
}
test_time_sanity_remote () {
log "=================================================="
log "Test time sanity remote..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
# create a snapshot with the same name as one on the source, but newer
sleep 1
zfs snapshot $DEST_POOL/a@zfs-auto-snap_daily6
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --remote-mode ssh --remote-user "root" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --ssh-options ""
check_result $TIME_SANITY_FAIL $?
general_test_teardown
}
test_invalid_mode () {
log "=================================================="
log "Test invalid mode..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
zfs set $ZFS_MODE_PROPERTY=lol $SOURCE_POOL/a
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --remote-mode ssh --remote-user "root" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090
check_result $MODE_INVALID $?
general_test_teardown
}
test_nested () {
log "=================================================="
log "Test successful nested backup..."
log "=================================================="
general_test_setup
create_snapshots
nested_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --nest-name-property "furneaux:backupnestname" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $SUCCESS $?
general_test_teardown
}
test_zfs_send_fail () {
log "=================================================="
log "Test ZFS send failure..."
log "=================================================="
general_test_setup
create_snapshots
root_setup
zfs destroy $SOURCE_POOL/a@zfs-auto-snap_daily7
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-mode ssh --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --remote-user "root" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --ssh-options ""
check_result $SEND_RECV_FAIL $?
general_test_teardown
}
test_path_on_top_level () {
log "=================================================="
log "Test path set on top level dataset..."
log "=================================================="
general_test_setup
create_snapshots
zfs set $ZFS_MODE_PROPERTY=path $SOURCE_POOL
zfs send -R $SOURCE_POOL@zfs-auto-snap_daily1 | sudo zfs recv -dF $DEST_POOL
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --nest-name-property "furneaux:backupnestname" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $ROOT_INVALID $?
general_test_teardown
}
test_root_on_non_top_level () {
log "=================================================="
log "Test root set on non top level dataset..."
log "=================================================="
general_test_setup
create_snapshots
zfs set $ZFS_MODE_PROPERTY=root $SOURCE_POOL/a
zfs set furneaux:backupnestname=n $SOURCE_POOL/a
zfs send -R $SOURCE_POOL/a@zfs-auto-snap_daily1 | sudo zfs recv -F $DEST_POOL/n/a
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --nest-name-property "furneaux:backupnestname" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $SUCCESS $?
general_test_teardown
}
test_root () {
log "=================================================="
log "Test successful root backup..."
log "=================================================="
general_test_setup
create_snapshots
root_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --nest-name-property "furneaux:backupnestname" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $SUCCESS $?
general_test_teardown
}
test_no_nest_name () {
log "=================================================="
log "Test no nest name..."
log "=================================================="
general_test_setup
create_snapshots
zfs set $ZFS_MODE_PROPERTY=root $SOURCE_POOL
zfs send -R $SOURCE_POOL@zfs-auto-snap_daily1 | sudo zfs recv $DEST_POOL/n/$SOURCE_POOL
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --nest-name-property "furneaux:backupnestname" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $NEST_NAME_MISSING $?
general_test_teardown
}
test_lockfile () {
log "=================================================="
log "Test lockfile..."
log "=================================================="
echo $$ > $LOCK_FILE
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-mode mbuffer --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --remote-user "root" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090
check_result $LOCK_FILE_PRESENT $?
rm $LOCK_FILE
}
test_ignore_lockfile () {
log "=================================================="
log "Test ignore lockfile..."
log "=================================================="
general_test_setup
path_setup
echo $$ > $LOCK_FILE
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --ignore-lock --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --remote-user "root" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $SUCCESS $?
general_test_teardown
}
test_ssh () {
log "=================================================="
log "Test successful ssh backup..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-mode ssh --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --remote-user "root" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --ssh-options ""
check_result $SUCCESS $?
general_test_teardown
}
test_mbuffer () {
log "=================================================="
log "Test successful mbuffer backup..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-mode mbuffer --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --remote-user "root" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090
check_result $SUCCESS $?
general_test_teardown
}
test_backup_disabled () {
log "=================================================="
log "Test backup disabled..."
log "=================================================="
general_test_setup
create_snapshots
path_setup
zfs set $ZFS_MODE_PROPERTY=off $SOURCE_POOL/a
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-mode mbuffer --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --remote-user "root" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090
check_result $SUCCESS $?
general_test_teardown
}
test_mbuffer_auto_blocksize () {
log "=================================================="
log "Test auto mbuffer blocksize..."
log "=================================================="
general_test_setup
zfs set recordsize=1M $SOURCE_POOL/a
create_snapshots
path_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-mode mbuffer --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --remote-user "root" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "auto" --mbuffer-buffer-size "1G" --mbuffer-port 9090
check_result $SUCCESS $?
general_test_teardown
}
test_up_to_date () {
log "=================================================="
log "Test up to date..."
log "=================================================="
general_test_setup
path_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $SUCCESS $?
general_test_teardown
}
test_missing_property () {
log "=================================================="
log "Test missing property..."
log "=================================================="
general_test_setup
path_setup
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --mode-property "lol:thisaintright" --remote-pool "$DEST_POOL" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $NO_DATASETS $?
general_test_teardown
}
test_invalid_argument () {
log "=================================================="
log "Test invalid argument..."
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --lolnope
check_result $SUCCESS $?
}
test_remote_mode_invalid () {
log "=================================================="
log "Test remote mode invalid"
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode lol
check_result $CONFIG_INVALID $?
}
test_snapshot_pattern_missing () {
log "=================================================="
log "Test snapshot pattern missing"
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $CONFIG_INVALID $?
}
test_mode_property_missing () {
log "=================================================="
log "Test mode property missing"
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $CONFIG_INVALID $?
}
test_mbuffer_block_size_missing () {
log "=================================================="
log "Test mbuffer block size missing"
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh
check_result $CONFIG_INVALID $?
}
test_mbuffer_port_missing () {
log "=================================================="
log "Test mbuffer port missing"
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port "" --remote-mode ssh
check_result $CONFIG_INVALID $?
}
test_mbuffer_buffer_size_missing () {
log "=================================================="
log "Test mbuffer buffer size missing"
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "" --mbuffer-port 9090 --remote-mode ssh
check_result $CONFIG_INVALID $?
}
test_remote_user_missing () {
log "=================================================="
log "Test remote user missing"
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-pool "$DEST_POOL" --mode-property "$ZFS_MODE_PROPERTY" --snapshot-pattern "zfs-auto-snap_daily" --mbuffer-block-size "128k" --mbuffer-buffer-size "1G" --mbuffer-port 9090 --remote-mode ssh --remote-user ""
check_result $CONFIG_INVALID $?
}
test_all_config_missing () {
log "=================================================="
log "Test all config missing"
log "=================================================="
./zfs-backup-manager.sh --config "zfs-backup-manager.conf" --remote-host "localhost" --remote-pool "" --mode-property "" --snapshot-pattern "" --mbuffer-block-size "" --mbuffer-buffer-size "" --mbuffer-port "" --remote-mode lol --remote-user ""
check_result $CONFIG_INVALID $?
}
test_config_file_missing () {
log "=================================================="
log "Test config file missing"
log "=================================================="
./zfs-backup-manager.sh --config "not-a-real-file.conf"
check_result $CONFIG_INVALID $?
}
print_help () {
echo "Usage: $(basename "$0") [--fail-fast] [--cleanup]"
echo " --fail-fast Stop testing on the first failure."
echo " --cleanup Cleanup after a failed test run."
exit 0
}
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--fail-fast)
FAIL_FAST=1
;;
--cleanup)
general_test_teardown
exit 0
;;
-h|--help)
print_help
;;
*)
log "Error: Invalid argument: \"$key\""
print_help
;;
esac
shift
done
log "ZFS Backup Manager Tests Starting..."
log ""
# negative tests
test_lockfile
test_invalid_argument
test_remote_mode_invalid
test_snapshot_pattern_missing
test_mode_property_missing
test_mbuffer_block_size_missing
test_mbuffer_port_missing
test_mbuffer_buffer_size_missing
test_remote_user_missing
test_all_config_missing
test_config_file_missing
test_invalid_mode
test_missing_property
test_missing_nest_name_property
test_path_on_top_level
test_no_nest_name
test_no_pattern_match
test_no_pattern_match_remote
test_remote_ahead_of_local
test_time_sanity_local
test_time_sanity_remote
test_zfs_send_fail
# positive tests
test_simulation
test_ignore_lockfile
test_additional_options
test_backup_disabled
test_nested
test_local
test_ssh
test_mbuffer
test_mbuffer_auto_blocksize
test_root
test_root_on_non_top_level
test_chain_backup_local
test_chain_backup_ssh
test_chain_backup_mbuffer
test_up_to_date
log ""
log "$TOTAL_TESTS total tests. $PASS_TESTS passed, $FAIL_TESTS failed."
log ""
log "All tests complete. Exiting."
exit 0