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

Run Pre- and post-hooks only once for a DB instance with split database files #368

Open
Cheezzhead opened this issue Sep 17, 2024 · 0 comments

Comments

@Cheezzhead
Copy link

Description of the feature
Currently, I use DBXX_SPLIT_DB=FALSE to back up all databases of an instance to a single file. My pre- and post-backup hooks are used to send a ping to a healthchecks instance (see below for the script), all working as expected.

However, if I want to split the backups to individual files (with DBXX_SPLIT_DB=TRUE), the pre- and post scripts are executed for every database, resulting in a separate ping (and thus a separate healthcheck) for each one. In my current environment, this would result in approximately 30-40 checks, cluttering up my healthchecks project while providing very little benefit.

I don't know how feasible this is to implement w.r.t. the workflow of the app, but if there is a possibility to execute the pre- and post scripts once for every database instance, it would provide the possibility to have separate dumps for each database while only sending one ping for each instance.

Benftits of feature
I haven't seen many other examples of script hooks, but I imagine they're generally used to send notifications or pings to a connected service. If we can reduce the number of notifications sent by this script without changing the functionality, I think this would be a benefit to anyone using a notification delivery service.

Additional context
Pre-backup script:

#!/bin/bash

# Note: Requires the environment variables HEALTHCHECK_DOMAIN and HEALTHCHECK_PING_KEY[_FILE]

# Define command output to send to Healthchecks
# See: https://github.com/tiredofit/docker-db-backup#pre-backup
log="'${1}' Backup Starting on ${2} for ${3} at ${4}. Filename: ${5}"

# Define slug of job
slug="$2-$3-backup"

# Read ping key from file if necessary
if [[ -n "${HEALTHCHECK_PING_KEY_FILE:-}" && -f "$HEALTHCHECK_PING_KEY_FILE" ]]; then
    ping_key=$(cat "$HEALTHCHECK_PING_KEY_FILE")
elif [[ -n "${HEALTHCHECK_PING_KEY:-}" ]]; then
    ping_key=$HEALTHCHECK_PING_KEY
else
    echo 'No ping key supplied!'; exit 1
fi

# Send update to healthchecks
# See: https://healthchecks.io/docs/measuring_script_run_time/
curl -fsS -m 30 --retry 5 --data-raw "$log" "${HEALTHCHECK_DOMAIN}/ping/${ping_key}/${slug}/start?create=1"

Post-backup script:

#!/bin/bash

# Note: Requires the environment variables HEALTHCHECK_DOMAIN and HEALTHCHECK_PING_KEY[_FILE]

# Define command output to send to Healthchecks
# See: https://github.com/tiredofit/docker-db-backup#post-backup
log="${2} Backup Completed (exit code: ${1}) on ${3} for ${4} on ${5} ending ${6} for a duration of ${7} seconds. Filename: ${8} Size: ${9} bytes MD5: ${10}"

# Define slug of job
slug="$3-$4-backup"

# Read ping key from file if necessary
if [[ -n "${HEALTHCHECK_PING_KEY_FILE:-}" && -f "$HEALTHCHECK_PING_KEY_FILE" ]]; then
    ping_key=$(cat "$HEALTHCHECK_PING_KEY_FILE")
elif [[ -n "${HEALTHCHECK_PING_KEY:-}" ]]; then
    ping_key=$HEALTHCHECK_PING_KEY
else
    echo 'No ping key supplied!'; exit 1
fi

# Send update to healthchecks
# See: https://hc.bpvr.nl/docs/signaling_failures/
curl -fsS -m 30 --retry 5 --data-raw "$log" "${HEALTHCHECK_DOMAIN}/ping/${ping_key}/${slug}/$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant