-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrestic-pushover.sh
executable file
·70 lines (58 loc) · 2.6 KB
/
restic-pushover.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
################################################################################
# Restic Backup Notifier #
################################################################################
# This script notifies you when restic runs successfully or unsucessfully via #
# Pushover. #
################################################################################
# TO RUN: #
# - Download and change the settings to the right values. #
# - You will need a Pushover user key and application key. #
# - You will need to have the restic repository password set in an enviromental#
# variable. You can do so in this file via RESTIC_PASSWORD or #
# RESTIC_PASSWORD_FILE. #
################################################################################
# Made by Zachary DuBois. Licensed under MIT. #
# https://zacharydubois.me #
# https://github.com/ZacharyDuBois/Random-Scripts/blob/master/LICENSE.md #
################################################################################
# !! Only pick one !!
export RESTIC_PASSWORD=""
#export RESTIC_PASSWORD_FILE=""
export RESTIC_REPOSITORY=""
# If you are using a cloud service, export the enviromental variables here as
# well. See:
# https://restic.readthedocs.io/en/stable/040_backup.html#environment-variables
pushoverAppKey=""
pushoverUserKey=""
# Restic backup command.
resticCmd="$(restic backup test-folder 2>&1)"
# Stop editing :)
resticExit=$?
pushoverSend() {
message=$1
curl -s --form-string "token=$pushoverAppKey" \
--form-string "user=$pushoverUserKey" \
--form-string "priority=0" \
--form-string "title=Restic Backup" \
--form-string "message=$message" \
--form-string "monospace=1" \
https://api.pushover.net/1/messages.json > /dev/null
pushoverStatus=$?
if [[ "$pushoverStatus" == 0 ]]; then
echo "Pushover message sent successfully: $message"
else
echo "Pushover failed to send message: $message"
fi
}
if [[ $resticExit == 0 ]]
then
summary=$(echo "$resticCmd" | sed -n '2,4p;5q')
snapshot=$(echo "$resticCmd" | sed '7q;d')
pushoverSend "Restic has backed up sucessfully!
$summary
$snapshot"
else
pushoverSend "Restic failed to back up. Error:
$resticCmd"
fi