#!/usr/bin/env bash # Restore a dump from export-db.sh on the server, replacing what's there. # deploy/import-db.sh set -euo pipefail cd "$(dirname "$0")/.." file="${1:?usage: deploy/import-db.sh }" compose=(docker compose -f docker-compose.yml -f docker-compose.prod.yml --env-file deploy/production.env) echo "This REPLACES the server's database with $file." read -r -p "Type 'replace' to continue: " answer [ "$answer" = "replace" ] || { echo "Aborted."; exit 1; } "${compose[@]}" stop api worker web "${compose[@]}" up -d postgres until "${compose[@]}" exec -T postgres pg_isready -U musicshare -d musicshare >/dev/null 2>&1; do sleep 1; done "${compose[@]}" exec -T postgres pg_restore -U musicshare -d musicshare --clean --if-exists --no-owner < "$file" # Apply any migrations newer than the dump, then bring everything back. "${compose[@]}" run --rm migrate "${compose[@]}" up -d echo "Restored. Everyone needs to sign in again (sessions are per-domain), and Plex/Jellyfin webhook URLs now use the new domain."