2022-11-29 15:15:37 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
set -a
|
|
|
|
. "/opt/services/backup/.env"
|
|
|
|
. "/opt/services/backup/.secret.env"
|
|
|
|
set +a
|
|
|
|
|
|
|
|
hc_url="https://hc-ping.com/$HC_UID"
|
|
|
|
|
|
|
|
curl -fsSL --retry 3 "$hc_url/start" >/dev/null
|
2023-12-04 15:47:00 +00:00
|
|
|
duration_start=$(date +%s)
|
2022-11-29 15:15:37 +00:00
|
|
|
|
|
|
|
BACKUP_LOCATION="/tmp/backup-misc"
|
|
|
|
|
|
|
|
rm -rf "$BACKUP_LOCATION"
|
|
|
|
mkdir -p "$BACKUP_LOCATION"
|
|
|
|
cd "$BACKUP_LOCATION" || exit
|
|
|
|
|
|
|
|
_hc_fail () {
|
|
|
|
curl -fsSL --retry 3 "$hc_url/fail"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_backup_prepare_postgres () {
|
|
|
|
mkdir -p "$BACKUP_LOCATION/postgres"
|
|
|
|
cd "$BACKUP_LOCATION/postgres" || exit
|
|
|
|
|
|
|
|
postgres_tables=$(sudo -u postgres psql -Atc "SELECT datname FROM pg_database WHERE datistemplate = false;")
|
|
|
|
|
|
|
|
for i in $postgres_tables
|
|
|
|
do
|
|
|
|
echo "dumping $i"
|
|
|
|
sudo -u postgres pg_dump "$i" | gzip >"pg_dump_$i.gz"
|
|
|
|
echo "done with $i"
|
|
|
|
echo ""
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "dumping all"
|
|
|
|
sudo -u postgres pg_dumpall | gzip >"pg_dumpall.gz"
|
|
|
|
}
|
|
|
|
|
|
|
|
_backup_prepare_mailcow () {
|
|
|
|
export MAILCOW_BACKUP_LOCATION="$BACKUP_LOCATION/mailcow"
|
|
|
|
mkdir -p "$MAILCOW_BACKUP_LOCATION"
|
|
|
|
/opt/mailcow-dockerized/helper-scripts/backup_and_restore.sh \
|
|
|
|
backup all --delete-days 3
|
|
|
|
}
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "preparing postgres"
|
|
|
|
time _backup_prepare_postgres >/tmp/backup-postgres.log || _hc_fail
|
|
|
|
echo ""
|
|
|
|
echo "preparing mailcow"
|
|
|
|
time _backup_prepare_mailcow >/tmp/backup-mailcow.log || _hc_fail
|
|
|
|
|
|
|
|
cd /opt/services/backup/
|
|
|
|
docker compose run --rm backup || _hc_fail
|
|
|
|
|
2023-12-04 15:47:00 +00:00
|
|
|
duration_end=$(date +%s)
|
2022-11-29 15:15:37 +00:00
|
|
|
curl -fsSL --retry 3 "$hc_url"
|
2023-12-04 15:47:00 +00:00
|
|
|
|
|
|
|
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"
|