العودة إلى الدرس

ملف العمل الأصلي

restore.sh

تحتفظ الشيفرة وصفحات الأمثلة القابلة للتشغيل بمعرّفاتها ونصوصها التجريبية الأصلية. يشرحها الدرس وإرشادات الملفات بلغتك.

#!/usr/bin/env bash
set -euo pipefail
read -r -s -p 'EMPTY DISPOSABLE TARGET connection URL (never production): ' RESTORE_DATABASE_URL
printf '\n'
psql "$RESTORE_DATABASE_URL" --no-psqlrc -c 'select current_database(), inet_server_addr(), inet_server_port();'
read -r -p 'Confirm you checked that this is the empty disposable target; type RESTORE-PRACTICE: ' confirmation
if [[ "$confirmation" != RESTORE-PRACTICE ]]; then exit 1; fi
# No --clean and no DROP: existing table causes an error rather than being overwritten.
pg_restore --dbname="$RESTORE_DATABASE_URL" --exit-on-error --no-owner --no-privileges backups/practice-notes.dump
psql "$RESTORE_DATABASE_URL" --no-psqlrc -v ON_ERROR_STOP=1 -c 'select id, note from public.backup_practice_notes order by id;'