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

Check backup errors and monitor status #58

Closed
tj57 opened this issue Aug 11, 2021 · 7 comments
Closed

Check backup errors and monitor status #58

tj57 opened this issue Aug 11, 2021 · 7 comments

Comments

@tj57
Copy link

tj57 commented Aug 11, 2021

It would be nice to check backup errors and monitor backup status to healthchecks.io in cloud or self-hosted using curl or wget.

https://stackoverflow.com/questions/6341321/how-to-check-if-postgresql-backup-was-successful

https://healthchecks.io/docs/bash/
https://healthchecks.io/docs/signaling_failures/

@prodrigestivill
Copy link
Owner

You already have an API using the curl "http://localhost:$HEALTHCHECK_PORT/" where you can have last backup result.

Is this what you are requiring?

@prodrigestivill prodrigestivill linked a pull request Feb 26, 2022 that will close this issue
@snyssen
Copy link

snyssen commented Aug 16, 2022

Hi, I'm reviving this issue because this is a feature I need too.

The linked pull request is perfect for my use case, but it does not seem to have made it into the final code for some reason?

An even better option imho would be to do something similar to this restic container I also use, which allows end users to provide a pre- and post-backup script. This could for example be useful for monitoring execution time as well as simply whether the backup fails or not. I could try and implement it myself then make a pull request here if you want.

@prodrigestivill
Copy link
Owner

Hello @snyssen, does the merged PR #47 closes this issue?

@snyssen
Copy link

snyssen commented Aug 20, 2022

Hi @prodrigestivill, thank you for your time!

Personally I would have preferred a more flexible solution with pre- and post-backup hooks as used in restic-backup-docker, so for example:

if [ -f "/hooks/pre-backup.sh" ]; then
    echo "Starting pre-backup script ..."
    /hooks/pre-backup.sh
fi
[...]
if [ -f "/hooks/post-backup.sh" ]; then
    echo "Starting post-backup script ..."
    /hooks/post-backup.sh $backupRC # $backupRC refers to the status code returned by the backup operation
fi

Meaning end users can input any arbitrary scripts they want be including them as volumes in their Docker implementation:

[...]
volumes:
    - ./hooks:/hooks

I prefer this feature because it allows me to not only ping healthchecks.io with status codes, but it also allows me to use its ability to measure execution time by pinging it on backup start and end. Here are my scripts for example:

  • pre-backup.sh
#! /bin/sh
curl --retry 3 https://hc-ping.com/"${HEALTHCHECK_ID}"/start
  • post-backup.sh
#! /bin/sh
curl --retry 3 https://hc-ping.com/"${HEALTHCHECK_ID}"/"$1" # $1 is the status code returned by the restic command

Having said that, the proposed solution is already pretty good for ensuring the backup is actually run on time, but I find it is still missing the ability to tell whether the backup was successful or not. I am willing to try and implement a solution on my end and then let you review it if you want, but I would like to know first if you would prefer that I try and implement my proposed solution (pre- and post-backup scripts), or if I should rather stick with the current implementation and simply provide an additionnal variables to indicate whether the backup was successful or not (so that variable can be used to build the $WEBHOOK_URL or the $WEBHOOK_EXTRA_ARGS ones).

@snyssen
Copy link

snyssen commented Aug 20, 2022

I realized I maybe gave a bit too much information, so I will clarify with this TL;DR:

PR #47 is good enough for me, except that it lacks the ability to signal whether the backup was successful or not, as it only signals whether it was run or not.

@prodrigestivill
Copy link
Owner

Closed after implementing #47 as separate default/example script.
Now more scripts can be added in the hooks folder and they are called for each diferent cases as documented in the README.

@snyssen
Copy link

snyssen commented Aug 20, 2022

Now that's perfect! Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants