Add backup to node003
This commit is contained in:
parent
3549901946
commit
7638b24bfe
4 changed files with 35 additions and 9 deletions
|
@ -1,2 +1,8 @@
|
|||
ansible_port: "{{ vault_node003.ansible_port }}"
|
||||
ansible_user: "{{ vault_node003.ansible_user }}"
|
||||
host_backup:
|
||||
backup:
|
||||
hc_uid: "{{ vault_node003.backup.hc_uid }}"
|
||||
uptime_kuma_token: "{{ vault_node003.backup.uptime_kuma_token }}"
|
||||
volumes:
|
||||
- minio_data
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
roles:
|
||||
- role: common
|
||||
tags: [always]
|
||||
- role: backup
|
||||
tags: [backup]
|
||||
- role: caddy
|
||||
tags: [caddy, reverse-proxy, webserver]
|
||||
|
||||
|
|
|
@ -6,18 +6,37 @@ set -a
|
|||
. "{{ service_path }}/service.env"
|
||||
set +a
|
||||
|
||||
duration_start=$(date +%s)
|
||||
_duration_get () {
|
||||
duration_end=$(date +%s)
|
||||
duration=$((duration_end - duration_start))
|
||||
}
|
||||
|
||||
hc_url="https://hc-ping.com/$HC_UID"
|
||||
uptime_kuma_url="https://status.serguzim.me/api/push/$UPTIME_KUMA_TOKEN"
|
||||
_hc_ping () {
|
||||
curl -fsSL --retry 3 "$hc_url$1" >/dev/null
|
||||
}
|
||||
_uptime_kuma_ping () {
|
||||
duration=_duration_get
|
||||
curl -fsSL --retry 3 \
|
||||
--url-query "status=$1" \
|
||||
--url-query "msg=$2" \
|
||||
--url-query "ping=${duration}000" \
|
||||
"$uptime_kuma_url" >/dev/null
|
||||
}
|
||||
|
||||
_hc_fail () {
|
||||
_fail () {
|
||||
_hc_ping "/fail"
|
||||
_uptime_kuma_ping "down" "$1"
|
||||
exit 1
|
||||
}
|
||||
_success () {
|
||||
_hc_ping
|
||||
_uptime_kuma_ping "up" "backup successful"
|
||||
}
|
||||
|
||||
_hc_ping "/start"
|
||||
duration_start=$(date +%s)
|
||||
|
||||
BACKUP_LOCATION="$(mktemp -d)"
|
||||
export BACKUP_LOCATION
|
||||
|
@ -28,17 +47,13 @@ for file in "{{ service_path }}/backup.d/"*
|
|||
do
|
||||
echo ""
|
||||
echo "running $file"
|
||||
time "$file" || _hc_fail
|
||||
time "$file" || _fail "fail while running $file"
|
||||
done || true
|
||||
|
||||
cd "{{ service_path }}"
|
||||
docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _hc_fail
|
||||
docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _fail "fail during restic backup"
|
||||
|
||||
duration_end=$(date +%s)
|
||||
_hc_ping
|
||||
|
||||
duration=$((duration_end - duration_start))
|
||||
curl -fsSL --retry 3 "https://status.serguzim.me/api/push/$UPTIME_KUMA_TOKEN?status=up&msg=OK&ping=${duration}000"
|
||||
_success
|
||||
|
||||
rm -rf "$BACKUP_LOCATION"
|
||||
|
||||
|
|
|
@ -23,6 +23,9 @@ backup_compose:
|
|||
app:
|
||||
build:
|
||||
context: .
|
||||
entrypoint:
|
||||
- /usr/bin/restic
|
||||
- --retry-lock=1m
|
||||
restart: never
|
||||
hostname: "{{ ansible_facts.hostname }}"
|
||||
volumes: "{{ host_backup.backup.volumes | map_backup_volumes }}"
|
||||
|
|
Reference in a new issue