2023-03-14 18:32:14 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2024-10-25 04:35:59 +00:00
|
|
|
hostname=$(cat /etc/hostname)
|
|
|
|
|
2023-03-14 18:32:14 +00:00
|
|
|
# Get secrets from files
|
|
|
|
# Insecure, but there's not much I can do about it
|
|
|
|
# It's duplicity's fault!
|
2023-05-17 12:33:44 +00:00
|
|
|
export PASSPHRASE=$(cat "${DUPLICITY_PASSPHRASE_FILE}")
|
2023-03-14 18:32:14 +00:00
|
|
|
|
2023-05-17 12:36:47 +00:00
|
|
|
echo "Launched in backup mode, performing backup..." >> /dev/stderr
|
2024-10-24 08:38:59 +00:00
|
|
|
|
|
|
|
if [ -n "${NTFY}" ]; then
|
|
|
|
echo "Sending ntfy backup start notification..." >> /dev/stderr
|
|
|
|
curl "${NTFY}" \
|
|
|
|
--silent \
|
|
|
|
--header "X-Title: Backup started" \
|
|
|
|
--data "Duplicity is attempting to perform a backup to **${DUPLICITY_TARGET_URL}**..." \
|
|
|
|
--header "X-Priority: min" \
|
2024-10-25 04:35:59 +00:00
|
|
|
--header "X-Tags: arrow_heading_up,duplicity,container-${hostname},${NTFY_TAGS}" \
|
|
|
|
--header "Content-Type: text/markdown" \
|
|
|
|
>/dev/null
|
2024-10-24 08:38:59 +00:00
|
|
|
fi
|
|
|
|
|
2024-10-25 04:35:59 +00:00
|
|
|
echo "Running duplicity..."
|
2023-05-17 12:36:47 +00:00
|
|
|
duplicity \
|
2024-10-25 01:09:24 +00:00
|
|
|
backup \
|
2024-10-24 08:38:59 +00:00
|
|
|
--allow-source-mismatch \
|
|
|
|
--full-if-older-than "${DUPLICITY_FULL_IF_OLDER_THAN}" \
|
|
|
|
/mnt \
|
|
|
|
"${DUPLICITY_TARGET_URL}"
|
|
|
|
|
|
|
|
backup_result=$?
|
|
|
|
|
|
|
|
if [ -n "${NTFY}" ]; then
|
|
|
|
case "$backup_result" in
|
|
|
|
0)
|
|
|
|
echo "Sending ntfy backup complete notification..." >> /dev/stderr
|
|
|
|
curl "${NTFY}" \
|
|
|
|
--silent \
|
|
|
|
--header "X-Title: Backup complete" \
|
|
|
|
--data "Duplicity has successfully performed a backup to **${DUPLICITY_TARGET_URL}**!" \
|
|
|
|
--header "X-Priority: low" \
|
2024-10-25 04:35:59 +00:00
|
|
|
--header "X-Tags: white_check_mark,duplicity,container-${hostname},${NTFY_TAGS}" \
|
|
|
|
--header "Content-Type: text/markdown" \
|
|
|
|
>/dev/null
|
2024-10-24 08:38:59 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Sending ntfy backup failed notification..." >> /dev/stderr
|
|
|
|
curl "${NTFY}" \
|
|
|
|
--silent \
|
|
|
|
--header "X-Title: Backup failed" \
|
|
|
|
--data "Duplicity failed to perform a backup to **${DUPLICITY_TARGET_URL}**, and exited with status code **${backup_result}**." \
|
|
|
|
--header "X-Priority: max" \
|
2024-10-25 04:35:59 +00:00
|
|
|
--header "X-Tags: sos,duplicity,container-${hostname},${NTFY_TAGS}" \
|
|
|
|
--header "Content-Type: text/markdown" \
|
|
|
|
>/dev/null
|
2024-10-24 08:38:59 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|