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:

  1. Read the credentials: cat /tmp/.env
  2. Export them: export $(cat /tmp/.env | xargs)
  3. Create a fresh database for the restore:

createdb -U appuser -h localhost appdb_restored

  1. Restore from the backup:

psql -U appuser -h localhost appdb_restored < /tmp/provided_backup.sql

  1. Verify the restore worked — count the users table rows:

psql -U appuser -h localhost appdb_restored -c "SELECT COUNT(*) FROM users;"

  1. Write the user count number to /tmp/restore_check.txt

Commands to learn: psql, createdb, pg_dump, database restore workflow

Run check when done.