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

Allow command hooks to provide additional status output #242

Open
garethgeorge opened this issue Apr 22, 2024 · 0 comments
Open

Allow command hooks to provide additional status output #242

garethgeorge opened this issue Apr 22, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@garethgeorge
Copy link
Owner

garethgeorge commented Apr 22, 2024

Tl;dr logs are captured for command hooks today but these are verbose and intended to capture "everything" for debugging. Command hooks should be able to provide concise summaries (viewable at a glance in the UI) of their result.

Proposal

command hooks should be exec'd with an extra open file descriptor (fd 3) where a command hook can write status information. A command hook can set it's exit status by exiting with 0 (success) or non-zero (failure).

fd3 will be a unix pipe consumed by backrest and buffered in memory. The message written here will be stored in the operation representing the hook and will be presented in the UI.

A hypothetical usage example:

#!/bin/bash
if ping -q -c 1 -W 1 google.com >/dev/null; then
  echo "Internet connection is up" &>3 
  exit 0
else
  echo "Internet connection is down" &>3
  exit 1
fi

will skip (or not skip) a backup based on the result of a ping to google.com and writes a descriptive status message to fd3 which will be viewable in the UI for a user to easily understand the result.

or more simply

echo "FOO" &>3

writes text to file descriptor 3 in a shell script.

The ultimate goal is for Backrest to facilitate a basic scripting model (built on unix principles) for users to customize backup scheduling, I'll try to collect a cookbook of worked-out scripts at https://garethgeorge.github.io/backrest/cookbooks/command-hook-examples .

Note: ExtraFiles is a Unix only feature, this will not be supported on Windows

@garethgeorge garethgeorge added the enhancement New feature or request label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant