1Feature: Backup hooks
2
3 Keld can run backup-specific shell commands before and after restic backup.
4 These hooks let users prepare generated backup inputs, such as database
5 dumps, and clean up generated files after restic has attempted the backup.
6
7 Background:
8 Given the selected preset supplies backup paths
9
10 Rule: Backup hooks are resolved by the most-specific matching configuration
11
12 Scenario: Most-specific hook keys override inherited hook keys
13 Given backup hooks are configured in multiple matching sections
14 When the backup configuration is resolved
15 Then the pre-hooks come from the most-specific section that defines pre-hooks
16 And the post-hooks come from the most-specific section that defines post-hooks
17 And the hooks are not passed to restic as flags
18
19 Scenario: Omitted hook keys inherit less-specific hooks
20 Given backup hooks are configured in a less-specific matching section
21 And the most-specific matching section omits hook keys
22 When the backup configuration is resolved
23 Then the inherited pre-hooks are used
24 And the inherited post-hooks are used
25
26 Scenario: Empty hook lists clear inherited hooks
27 Given backup hooks are configured in a less-specific matching section
28 And the most-specific matching section clears hook keys
29 When the backup configuration is resolved
30 Then no pre-hooks are configured
31 And no post-hooks are configured
32
33 Rule: Pre-hooks run before restic backup
34
35 Scenario: Pre-hooks complete successfully
36 Given the backup configuration includes pre-hooks
37 When keld runs the backup
38 Then each pre-hook runs before restic backup
39 And restic backup is attempted
40
41 Scenario: A pre-hook fails
42 Given the backup configuration includes a failing pre-hook
43 When keld runs the backup
44 Then restic backup is not attempted
45 And post-hooks are not run
46 And keld reports the pre-hook failure
47
48 Rule: Post-hooks run after restic backup is attempted
49
50 Scenario Outline: Post-hooks receive the restic outcome
51 Given the backup configuration includes post-hooks
52 And restic backup exits with code <code>
53 When keld runs the backup
54 Then each post-hook runs after restic backup
55 And each post-hook receives KELD_RESTIC_EXIT_CODE set to "<code>"
56 And each post-hook receives KELD_RESTIC_STATUS set to "<status>"
57 And keld exits with code <code>
58
59 Examples:
60 | code | status |
61 | 0 | success |
62 | 1 | fatal |
63 | 2 | runtime_error |
64 | 3 | partial |
65 | 10 | repository_missing |
66 | 11 | locked |
67 | 12 | wrong_password |
68 | 130 | interrupted |
69 | 143 | terminated |
70 | 99 | unknown_failure |
71
72 Scenario: A post-hook fails after restic fails
73 Given the backup configuration includes a failing post-hook
74 And restic backup exits with code 3
75 When keld runs the backup
76 Then keld exits with code 3
77 And keld reports the post-hook failure
78
79 Scenario: Restic fails to start after pre-hooks complete
80 Given the backup configuration includes pre-hooks and post-hooks
81 And restic backup fails to start
82 When keld runs the backup
83 Then each post-hook runs after the failed restic start
84 And each post-hook receives KELD_RESTIC_STATUS set to "start_failed"
85 And each post-hook receives no KELD_RESTIC_EXIT_CODE
86 And keld reports the restic start failure
87
88 Rule: Command previews show hooks without runtime-only outcome values
89
90 Scenario: Showing the command for a backup with hooks
91 Given the backup configuration includes pre-hooks and post-hooks
92 When keld shows the resolved backup command
93 Then the output includes the configured pre-hooks
94 And the output includes the configured post-hooks
95 And the output does not include KELD_RESTIC_EXIT_CODE
96 And the output does not include KELD_RESTIC_STATUS