Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support restic check operation #303

Merged
merged 14 commits into from
May 27, 2024
Merged
11 changes: 4 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ jobs:
with:
go-version: "1.21"

- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Generate
run: go generate ./...
- name: Create Fake WebUI Sources
run: |
mkdir -p webui/dist
touch webui/dist/index.html.gz

- name: Build
run: go build ./...
Expand Down
9 changes: 4 additions & 5 deletions cmd/backrestmon/backrestmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ func main() {
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "ENV=production")

pro, pwo := io.Pipe()
pre, pwe := io.Pipe()
cmd.Stdout = pwo
cmd.Stderr = pwe
pr, pw := io.Pipe()
cmd.Stdout = pw
cmd.Stderr = pw

go func() {
io.Copy(l, io.MultiReader(pro, pre))
io.Copy(l, pr)
}()

if err := cmd.Start(); err != nil {
Expand Down
21 changes: 20 additions & 1 deletion docs/content/2.docs/2.hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ Backrest supports hooks in response to operation lifecycle events e.g. in respon
Available event types are

- `CONDITION_ANY_ERROR` any operation has failed.
- `CONDITION_SNAPSHOT_START` the start of a backup operation (e.g. corresponds to a call to `restic backup`)
- `CONDITION_SNAPSHOT_START` the start of a backup operation (e.g. corresponds to a call to `restic backup`, supports error behavior)
- `CONDITION_SNAPSHOT_END` the end of a backup operation (e.g. corresponds to `restic backup` completing). Note that Snapshot End will still be called if a backup failed.
- `CONDITION_SNAPSHOT_ERROR` an error occurred during a backup operation (e.g. `restic backup` returned a non-zero exit code OR invalid output).
- `CONDITION_SNAPSHOT_WARNING` a warning occurred during a backup operation (e.g. a file was partially read).
- Prune hooks:
- `CONDITION_PRUNE_START` the start of a prune operation (e.g. corresponds to a call to `restic prune`, supports error behavior)
- `CONDITION_PRUNE_SUCCESS` the end of a prune operation e.g. `restic prune` completed successfully.
- `CONDITION_PRUNE_ERROR` an error occurred during a prune operation (e.g. `restic prune` returned a non-zero exit code).
- Check hooks:
- `CONDITION_CHECK_START` the start of a check operation (e.g. corresponds to a call to `restic check`, supports error behavior)
- `CONDITION_CHECK_SUCCESS` the end of a check operation e.g. `restic check` completed successfully.
- `CONDITION_CHECK_ERROR` an error occurred during a check operation (e.g. `restic check` returned a non-zero exit code).

## Notification Services

Expand All @@ -22,6 +30,17 @@ Available event types are
| Shoutrrr | https://containrrr.dev/shoutrrr/v0.8/ |
| Command | See command cookbook |


## Error Behavior

Some hooks can specify an error behavior (today this is only command hooks). This determines what happens when the hook generates an error.

The available error behaviors are:

- `ON_ERROR_IGNORE` - ignore the error and continue running hooks and the operation.
- `ON_ERROR_CANCEL` - cancel the operation and do not run any further hooks. The operation is marked as cancelled.
- `ON_ERROR_FATAL` - cancel the operation and do not run any further hooks. The operation is marked as failed and error handler hooks may be triggered.

## Using Templates

Most hooks will generate either a notification or execute a script. The script / notification is typically formatted as a Go template. The https://pkg.go.dev/text/template docs provide a very technical overview of Go template capabilities. See below for info about the available variables and for some examples.
Expand Down
313 changes: 184 additions & 129 deletions gen/go/v1/config.pb.go

Large diffs are not rendered by default.

319 changes: 203 additions & 116 deletions gen/go/v1/operations.pb.go

Large diffs are not rendered by default.

Loading
Loading