Move _ansible directory into main directory
This commit is contained in:
parent
519882db43
commit
40742e3214
124 changed files with 246 additions and 141 deletions
roles/backup/templates
4
roles/backup/templates/backup.service.j2
Normal file
4
roles/backup/templates/backup.service.j2
Normal file
|
@ -0,0 +1,4 @@
|
|||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart={{ service_path }}/backup.sh
|
||||
WorkingDirectory={{ service_path }}
|
50
roles/backup/templates/backup.sh.j2
Executable file
50
roles/backup/templates/backup.sh.j2
Executable file
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
set -a
|
||||
. "{{ service_path }}/service.env"
|
||||
set +a
|
||||
|
||||
hc_url="https://hc-ping.com/$HC_UID"
|
||||
_hc_ping () {
|
||||
curl -fsSL --retry 3 "$hc_url$1" >/dev/null
|
||||
}
|
||||
|
||||
_hc_fail () {
|
||||
_hc_ping "/fail"
|
||||
exit 1
|
||||
}
|
||||
|
||||
_hc_ping "/start"
|
||||
duration_start=$(date +%s)
|
||||
|
||||
BACKUP_LOCATION="$(mktemp -d)"
|
||||
export BACKUP_LOCATION
|
||||
cd "$BACKUP_LOCATION" || exit
|
||||
|
||||
shopt -s nullglob
|
||||
for file in "{{ service_path }}/backup.d/"*
|
||||
do
|
||||
echo ""
|
||||
echo "running $file"
|
||||
time "$file" || _hc_fail
|
||||
done || true
|
||||
|
||||
cd "{{ service_path }}"
|
||||
docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _hc_fail
|
||||
|
||||
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"
|
||||
|
||||
rm -rf "$BACKUP_LOCATION"
|
||||
|
||||
echo "forgetting old backups for $(hostname)"
|
||||
docker compose run --rm app forget --host "$(hostname)" --prune \
|
||||
--keep-daily 14 \
|
||||
--keep-weekly 28 \
|
||||
--keep-monthly 12 \
|
||||
--keep-yearly 2
|
Reference in a new issue