fix: restic
This commit is contained in:
parent
d2258d5808
commit
2b5e12b937
5 changed files with 40 additions and 29 deletions
|
@ -7,9 +7,12 @@ ntfy_token=""
|
|||
help()
|
||||
{
|
||||
echo "Options:"
|
||||
echo "-t Set the title of a message."
|
||||
echo "-m Your message."
|
||||
echo "-p Notification priority, 1-5, 5 is the highest. (Optional)"
|
||||
echo "-e Choose emoji. (https://ntfy.sh/docs/emojis/?h=emo)"
|
||||
echo "-s Set the token for a message from a file"
|
||||
echo "-u specify url"
|
||||
echo "-h Print this help."
|
||||
echo
|
||||
echo "If you want to show if the last command was successful or not, you can do something like this:"
|
||||
|
@ -18,12 +21,14 @@ help()
|
|||
}
|
||||
|
||||
|
||||
while getopts "t:m:p:e:h" option; do
|
||||
while getopts "t:m:p:e:s:u:h" option; do
|
||||
case $option in
|
||||
t) ntfy_topic=${OPTARG};;
|
||||
m) ntfy_message=${OPTARG};;
|
||||
p) ntfy_prio=${OPTARG};;
|
||||
e) ntfy_emoji=${OPTARG};;
|
||||
t) ntfy_topic="$OPTARG";;
|
||||
m) ntfy_message="$OPTARG";;
|
||||
p) ntfy_prio="$OPTARG";;
|
||||
e) ntfy_emoji="$OPTARG";;
|
||||
s) ntfy_token="$(cat $OPTARG)";;
|
||||
u) ntfy_url="$OPTARG";;
|
||||
h) help
|
||||
exit;;
|
||||
\?)
|
||||
|
@ -85,10 +90,11 @@ else
|
|||
ntfy_auth=""
|
||||
fi
|
||||
|
||||
curl -s \
|
||||
curl \
|
||||
-X POST \
|
||||
-H "$ntfy_auth" \
|
||||
-H "Title: $ntfy_topic" \
|
||||
-H "Tags: $ntfy_tag" \
|
||||
-H "Priority: $ntfy_prio" \
|
||||
-d "$ntfy_message" \
|
||||
"$1" > /dev/null
|
||||
"$ntfy_url"
|
|
@ -1,13 +1,17 @@
|
|||
#!/bin/sh
|
||||
|
||||
/neb/common/ntfy.sh -m "performing backup..." -e "warning" https://push.ixvd.net/infra-backups
|
||||
ntfy() {
|
||||
sh /neb/common/ntfy.sh -s "/neb/secrets/ntfy/ixvd-backups" -u "https://push.ixvd.net/ixvd-backups" "$@"
|
||||
}
|
||||
|
||||
ntfy -m "performing backup..."
|
||||
if restic \
|
||||
-r "sftp://ixvd_backup_storage//backups/restic-$(hostname)" \
|
||||
-p "/neb/secrets/restic/$(hostname).secret" \
|
||||
backup \
|
||||
--tag auto \
|
||||
/srv /home /etc; then
|
||||
/neb/common/ntfy.sh -m "backup succeeded" -e "warning" https://push.ixvd.net/infra-backups
|
||||
ntfy -m "backup succeeded"
|
||||
else
|
||||
/neb/common/ntfy.sh -p "urgent" -m "backup failed" -e "warning,skull" https://push.ixvd.net/infra-backups
|
||||
ntfy -m "backup failed" -e "warning,skull"
|
||||
fi
|
|
@ -1,14 +1,10 @@
|
|||
#!/bin/sh
|
||||
|
||||
notify() {
|
||||
curl \
|
||||
-X POST \
|
||||
-H "Authorization: $(cat ${NTFY_SECRET_FILE:-/etc/ixvd/secrets/ntfy/infra-backups})" \
|
||||
-d "$(hostname): $@" \
|
||||
https://push.ixvd.net/infra-backups
|
||||
ntfy() {
|
||||
sh /neb/common/ntfy.sh -s "/neb/secrets/ntfy/ixvd-backups" -u "https://push.ixvd.net/ixvd-backups" "$@"
|
||||
}
|
||||
|
||||
notify "forgetting old backups..."
|
||||
ntfy -m "forgetting old backups..."
|
||||
if restic \
|
||||
-r "sftp://ixvd_backup_storage//backups/restic-$(hostname)" \
|
||||
-p "/etc/ixvd/secrets/restic/$(hostname).secret" \
|
||||
|
@ -19,7 +15,7 @@ if restic \
|
|||
--keep-weekly 20 \
|
||||
--keep-monthly 6 \
|
||||
--keep-yearly 10; then
|
||||
notify "forget succeeded"
|
||||
ntfy -m "forget succeeded"
|
||||
else
|
||||
notify "forget failed"
|
||||
ntfy -m "forget failed" -e "warning,skull"
|
||||
fi
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
#!/bin/sh
|
||||
|
||||
notify() {
|
||||
curl \
|
||||
-X POST \
|
||||
-H "Title: $0" \
|
||||
-H "Priority: urgent" \
|
||||
-H "Tags: warning" \
|
||||
-d "$(hostname): $@" \
|
||||
https://push.ixvd.net/infra-backups
|
||||
ntfy() {
|
||||
sh /neb/common/ntfy.sh -s "/neb/secrets/ntfy/ixvd-backups" -u "https://push.ixvd.net/ixvd-backups" "$@"
|
||||
}
|
||||
|
||||
notify "pruning old backups..."
|
||||
ntfy -m "pruning old backups..."
|
||||
if restic \
|
||||
-r "sftp://ixvd_backup_storage//backups/restic-$(hostname)" \
|
||||
-p "/etc/ixvd/secrets/restic/$(hostname).secret" \
|
||||
prune; then
|
||||
notify -m "pruning succeeded"
|
||||
else
|
||||
notify -m "prune failed" -e "warning,skull"
|
||||
fi
|
5
setup.sh
5
setup.sh
|
@ -26,4 +26,7 @@ if ! [ -d "/neb" ]; then
|
|||
fi
|
||||
|
||||
if ! [ -d "/etc/cron.d/restic.crontab" ]; then
|
||||
echo "setting up
|
||||
echo "setting up restic cron"
|
||||
mkdir -p /etc/cron.d/
|
||||
cp /neb/common/restic/restic.crontab /etc/cron.d/restic.crontab
|
||||
fi
|
Loading…
Reference in a new issue