A decentralized music tracking and discovery platform built on AT Protocol 🎵 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
98
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: simplify backup script by removing size estimation and progress logging

+2 -63
+2 -63
tools/backup-xata.sh
··· 4 4 # exit if XATA_POSTGRES_URL is not set 5 5 : "${XATA_POSTGRES_URL:?Need to set XATA_POSTGRES_URL non-empty}" 6 6 7 - USE_PIGZ="${USE_PIGZ:-1}" 8 - GZIP_LEVEL="${GZIP_LEVEL:-9}" # compression level 1..9 9 - TS="$(date -u +%Y%m%d-%H%M%SZ)" 10 - OUT="xata-db-$TS.sql.gz" 11 - TMPDIR="${TMPDIR:-/tmp}" 12 - # ------------------------------------------------------------------------- 7 + BACKUP_NAME="xata-backup-$(date +%Y%m%d-%H%M%S).sql.gz" 13 8 14 - log() { printf "[%s] %s\n" "$(date -u +%H:%M:%SZ)" "$*" >&2; } 15 - 16 - # Cleanup on error/exit 17 - cleanup() { 18 - [[ -f "$TMPDIR/.est_bytes.$TS" ]] && rm -f "$TMPDIR/.est_bytes.$TS" || true 19 - } 20 - trap cleanup EXIT 21 - 22 - # Optional: estimate total DB size to feed pv -s <bytes> 23 - EST_BYTES="" 24 - if command -v psql >/dev/null 2>&1; then 25 - # -At: unaligned, tuples only. We ignore errors (lack of perms etc.) 26 - # Sum of table+index+toast for all relations in current DB 27 - # Note: This is an estimate of logical dump volume; actual dump size differs, 28 - # but it's good enough to give pv an ETA. 29 - set +e 30 - EST_BYTES="$(psql "$XATA_POSTGRES_URL" -Atc \ 31 - "SELECT COALESCE(SUM(pg_total_relation_size(c.oid)),0) 32 - FROM pg_class c 33 - JOIN pg_namespace n ON n.oid=c.relnamespace 34 - WHERE c.relkind IN ('r','p','m') AND n.nspname NOT IN ('pg_toast','pg_catalog','information_schema');" 2>/dev/null)" 35 - set -e 36 - # Validate it's an integer 37 - [[ "${EST_BYTES:-}" =~ ^[0-9]+$ ]] || EST_BYTES="" 38 - [[ -n "$EST_BYTES" ]] && echo -n "$EST_BYTES" > "$TMPDIR/.est_bytes.$TS" 39 - fi 40 - 41 - # Choose compressor 42 - COMPRESSOR="gzip -${GZIP_LEVEL}" 43 - if [[ "${USE_PIGZ}" = "1" ]] && command -v pigz >/dev/null 2>&1; then 44 - COMPRESSOR="pigz -${GZIP_LEVEL}" 45 - fi 46 - 47 - # Build the pipeline with progress 48 - # We want: pg_dump | pv [-s EST] | (gzip|pigz) > OUT 49 - log "Starting logical dump → ${OUT}" 50 - if command -v pv >/dev/null 2>&1; then 51 - if [[ -n "${EST_BYTES}" ]]; then 52 - # With size estimate (shows ETA) 53 - pg_dump --no-owner --no-privileges --format=plain "$XATA_POSTGRES_URL" \ 54 - | pv -ptebar -s "${EST_BYTES}" \ 55 - | eval "$COMPRESSOR" > "$OUT" 56 - else 57 - # Without size estimate (shows rate/elapsed) 58 - pg_dump --no-owner --no-privileges --format=plain "$XATA_POSTGRES_URL" \ 59 - | pv -ptebar \ 60 - | eval "$COMPRESSOR" > "$OUT" 61 - fi 62 - else 63 - log "pv not found; proceeding without live progress. Install 'pv' for a progress bar." 64 - pg_dump --no-owner --no-privileges --format=plain "$XATA_POSTGRES_URL" \ 65 - | eval "$COMPRESSOR" > "$OUT" 66 - fi 67 - 68 - # Integrity file 69 - log "Computing checksum" 70 - sha256sum "$OUT" > "$OUT.sha256" 9 + pg_dump $XATA_POSTGRES_URL --no-owner --no-acl | pv -pteba | gzip > "$BACKUP_NAME"