Add database backup script with daily cron and 7-day retention
pg_dump-based backup script deployed alongside compose file. Deploy script now installs a daily cron job (03:00) on Unraid automatically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
19
deploy.sh
19
deploy.sh
@@ -55,10 +55,13 @@ done
|
||||
info "All images built and pushed."
|
||||
|
||||
# ── Sync compose file to Unraid ──────────────────────────────────
|
||||
info "Copying docker-compose.prod.yml to Unraid..."
|
||||
info "Copying docker-compose.prod.yml and backup.sh to Unraid..."
|
||||
scp docker-compose.prod.yml "${UNRAID_SSH}:${UNRAID_DEPLOY_DIR}/docker-compose.yml" \
|
||||
|| error "Failed to copy compose file to Unraid."
|
||||
info "Compose file synced."
|
||||
scp backup.sh "${UNRAID_SSH}:${UNRAID_DEPLOY_DIR}/backup.sh" \
|
||||
|| error "Failed to copy backup script to Unraid."
|
||||
ssh "${UNRAID_SSH}" "chmod +x '${UNRAID_DEPLOY_DIR}/backup.sh'"
|
||||
info "Compose file and backup script synced."
|
||||
|
||||
# ── Ensure .env with Postgres password exists ────────────────────
|
||||
info "Checking for .env on Unraid..."
|
||||
@@ -72,6 +75,18 @@ ssh "${UNRAID_SSH}" "
|
||||
fi
|
||||
" || error "Failed to check/create .env on Unraid."
|
||||
|
||||
# ── Ensure daily backup cron job exists ───────────────────────────
|
||||
info "Checking for backup cron job on Unraid..."
|
||||
CRON_CMD="0 3 * * * ${UNRAID_DEPLOY_DIR}/backup.sh >> ${UNRAID_DEPLOY_DIR}/backups/cron.log 2>&1"
|
||||
ssh "${UNRAID_SSH}" "
|
||||
if ! crontab -l 2>/dev/null | grep -qF '${UNRAID_DEPLOY_DIR}/backup.sh'; then
|
||||
(crontab -l 2>/dev/null; echo '${CRON_CMD}') | crontab -
|
||||
echo 'Cron job installed (daily at 03:00)'
|
||||
else
|
||||
echo 'Cron job already exists, skipping'
|
||||
fi
|
||||
" || error "Failed to set up backup cron job on Unraid."
|
||||
|
||||
# ── Pull images and (re)start on Unraid ──────────────────────────
|
||||
info "Pulling images and starting containers on Unraid..."
|
||||
ssh "${UNRAID_SSH}" "cd '${UNRAID_DEPLOY_DIR}' && docker compose pull && docker compose up -d" \
|
||||
|
||||
Reference in New Issue
Block a user