KenKundert / emborg

Interactive command line interface to Borg Backup
GNU General Public License v3.0
94 stars 8 forks source link

POST log/stats to healthcheck.io upon completion #43

Closed ekool closed 3 years ago

ekool commented 3 years ago

Borgmatic has a really nice feature where it will do a POST to healthchecks.io upon job completion. The POST body contains the stats of the job, not just the exit value. It would be nice if Emborg had this ability as well.

KenKundert commented 3 years ago

Have you tried using the run_after_backup setting. You can run a curl command to ping healthchecks.io to indicate success. Instructions on how to construct the curl command can be found here:

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

So, adding something like the following to your Emborg config file should work:

run_after_backup = [ 
    'curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/your-uuid-here',
        # notify healthchecks.io that backsups were successful
]
ekool commented 3 years ago

Yes, I'm using exactly this... essentially emborg and borgmatic have that same function. But this is what the healthchecks.io looks like with borgmatic vs emborg. The details in the borgmatic version are most helpful as a quick way to look at historical data on previous runs.

borgmatic

vs emborg

emborg

ekool commented 3 years ago

As you can see, the emborg is setup to only send the exit status easily with the URL/$?

KenKundert commented 3 years ago

Ah, I see. Yeah, that should not be too difficult. Let me see what I can do.

KenKundert commented 3 years ago

I have upgraded Emborg on github. Can you try it out and see if it meets your needs. Once you have downloaded and installed the latest version from github, you can configure it to use healthchecks.io by adding your UUID into your configuration file as follows:

healthchecks_uuid = '51cb35d8-2975-110b-67a7-11b65d432027'

Then it should let healthchecks.io know when your backup is starting and when it finished and whether it succeeded or failed.

ekool commented 3 years ago

I tried and got the following

` emborg create --progress

Running Borg create command ... Traceback (most recent call last): File "/usr/local/bin/emborg", line 33, in sys.exit(load_entry_point('emborg==1.21.2', 'console_scripts', 'emborg')()) File "/usr/local/lib/python3.6/site-packages/emborg/main.py", line 103, in main cmd_name, args, settings, emborg_opts File "/usr/local/lib/python3.6/site-packages/emborg/command.py", line 153, in execute exit_status = cls.run(name, args if args else [], settings, options) File "/usr/local/lib/python3.6/site-packages/emborg/command.py", line 410, in run settings.hooks.backups_finish(borg) File "/usr/local/lib/python3.6/site-packages/emborg/hooks.py", line 45, in backups_finish hook.signal_end(borg) File "/usr/local/lib/python3.6/site-packages/emborg/hooks.py", line 99, in signal_end response = requests.post(url, data=payload.encode('utf-8')) AttributeError: 'NoneType' object has no attribute 'encode' `

It ran for a while and then popped out with this error.

KenKundert commented 3 years ago

Whoops. Sorry about that. I have fixed the code and updated the git repository. Please try again. Be aware that uploading the logfile to healthchecks.io will not work if you use the --progress option. With --progress the output of Borg goes to stdout and is not captured by Emborg, so it is not available to upload to healthchecks.io.

ekool commented 3 years ago

Worked like a charm!

Archive name: centmin2-root-backups-2021-06-18T11:13:02
Archive fingerprint: 62e64a5f71740cd1ff05ffd1888e5a6ec161955fe8c8607ee3f2381a0bbe6c88
Time (start): Fri, 2021-06-18 11:13:13
Time (end):   Fri, 2021-06-18 11:15:51
Duration: 2 minutes 38.69 seconds
Number of files: 838611
Utilization of max. archive size: 0%
------------------------------------------------------------------------------
                       Original size      Compressed size    Deduplicated size
This archive:              120.28 GB            107.27 GB            150.61 MB
All archives:                1.60 TB              1.45 TB            109.94 GB

                       Unique chunks         Total chunks
Chunk index:                  639866             12033588
KenKundert commented 3 years ago

Okay, do you need it in pypi right away? I am tempted to hold off for a while and add other monitoring services.

ekool commented 3 years ago

Okay, do you need it in pypi right away? I am tempted to hold off for a while and add other monitoring services.

Not in any hurry at all! Love the software. Please take your time.

KenKundert commented 3 years ago

Thanks!

KenKundert commented 3 years ago

I have updated pypi with the latest version.