Restore from a Backup
Use psql to restore a PostgreSQL backup into a fresh database.
A beginner Linux challenge worth 3 points. Solve it hands-on in a real Linux environment in your browser - no local setup, no fake shells.
The Challenge
Scenario: Disaster struck — the app database got corrupted after a bad migration. You have a backup at /tmp/provided_backup.sql. Restore it to get the service back online.
Your tasks:
- Read the credentials:
cat /tmp/.env - Export them:
export $(cat /tmp/.env | xargs) - Create a fresh database for the restore:
createdb -U appuser -h localhost appdb_restored
- Restore from the backup:
psql -U appuser -h localhost appdb_restored < /tmp/provided_backup.sql
- Verify the restore worked — count the users table rows:
psql -U appuser -h localhost appdb_restored -c "SELECT COUNT(*) FROM users;"
- Write the user count number to
/tmp/restore_check.txt
Commands to learn: psql, createdb, pg_dump, database restore workflow
Run check when done.