mirror of
https://github.com/Mak5er/Downloader-Bot
synced 2026-11-26 17:18:04 +08:00
Add postgres, db-init, and backup services to docker-compose. Migrate database from Neon DB to self-hosted PostgreSQL 17. - postgres:17-alpine with healthcheck and persistent volume - db-init: auto-restore from local dump or Backblaze B2 on first start - backup: scheduled pg_dump with B2 upload (daily at 3am) - Host-side scripts: backup.sh, restore.sh, cron-backup.sh - Fixed dynamic table ownership in restore (no hardcoded table names) - Fixed pg_restore to use docker cp instead of stdin pipe
28 lines
730 B
Bash
28 lines
730 B
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
echo "[backup] Starting backup service..."
|
|
|
|
B2_KEY_ID="${B2_KEY_ID:-}"
|
|
B2_APP_KEY="${B2_APP_KEY:-}"
|
|
BACKUP_CRON="${BACKUP_CRON:-0 3 * * *}"
|
|
|
|
# Authorize B2 if credentials provided
|
|
if [ -n "$B2_KEY_ID" ] && [ -n "$B2_APP_KEY" ]; then
|
|
echo "[backup] Authorizing B2..."
|
|
b2 authorize-account "$B2_KEY_ID" "$B2_APP_KEY"
|
|
echo "[backup] B2 authorized"
|
|
else
|
|
echo "[backup] WARNING: B2 credentials not set, local backups only"
|
|
fi
|
|
|
|
# Create local backup directory
|
|
mkdir -p /backups
|
|
|
|
# Write cron schedule
|
|
echo "${BACKUP_CRON} /backup.sh >> /var/log/backup.log 2>&1" > /etc/crontabs/root
|
|
|
|
echo "[backup] Cron schedule: ${BACKUP_CRON}"
|
|
echo "[backup] Starting cron daemon..."
|
|
exec crond -f -l 2
|