Mini lesson · English

How to back up and restore your website data

Download a real backup of supplied practice records, restore it into a separate empty practice target and check the recovered values.

Start the interactive lessonRead the lesson below

Who is this for?

People who want to understand and verify website-data recovery. The first exercise runs in a browser with ready data; PostgreSQL, Bash and migration commands are optional advanced study.

Before you start

A browser and the supplied local backup practice. No account, private data or database installation is needed for that exercise. An actual hosted-site backup additionally needs your own provider’s supported tools and access; the optional database workshop uses disposable targets only.

Estimated time: 24–41 min

Estimates for the supplied starter files with prerequisite accounts and tools ready. Setup, deployment queues and delivery/DNS waits take additional time. This is a one-table logical export exercise, not a complete production backup/PITR solution. Database accounts and tool installation take additional time.

What you will learn

  • Create a downloadable backup rather than relying on saved website code.
  • Restore into a separate practice target and compare actual records.
  • State which real website data and permissions the exercise does not cover.

Workshop files

Step 1

Choose what the backup protects

Website code and stored records are different things.

Open practice/index.html and inspect the supplied source records and the separate empty restore target. These are fictional local records, not your real website database.

Saving the website repository alone does not establish that form records or uploads are recoverable. Name the exact data this exercise covers.

A concrete example

A site’s code may be in Git while its customer records exist only in another service.

The local source starts with two fictional notes: ID 1, “Practice note: first visitor task”, and ID 2, “Practice note: saved contact preference”. The Add control supplies ID 3, “Restore check: turquoise notebook”. These exact English sample values are data to compare, not code to write.

Open the supplied local backup practice. Help me download the source-record backup, restore it into its separate empty target and compare exact IDs/text. Explain the local scope honestly: this is not a completed hosted database backup. If I later use the optional PostgreSQL scripts, inspect the source/empty target with me first and never run destructive commands or touch production.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Back up data by proving you can restore it

A backup file is useful only if its contents can produce the state you need.

Your Git repository may recover the website code while containing none of its database records or uploaded files. Data recovery needs its own plan.

This lesson exports one small PostgreSQL application table and restores it into a separate empty database. Keeping the scope narrow makes the first recovery test understandable; the scope table makes clear what it does not protect.

Worked example

The known note is “Restore check: turquoise notebook”. After restoration, we must read that exact value and its ID from the target, not merely see a nonempty dump file.

Extra implementation exercise

Your source code is in Git. Does that prove you can recover yesterday's form submissions?

Show a worked solution

No. The records live in a database outside the code repository. You need a data recovery source and evidence that it restores the expected records.

  • Separates application code from stored data.
  • Requires a data backup and restore check.

Step 2

Download a backup you can inspect

Create an actual file before clearing or changing any target.

Choose “Download backup” in the local practice. It creates practice-backup.json from the source notes. Keep that downloaded file; ask your assistant or a plain viewer to show the two record IDs and texts without changing them.

The source and restore target live only in this open page. Download before leaving or reloading, because the sample page is not persistent hosted storage. The next step restores your downloaded file into the separate target.

A concrete example

Before adding a record, the exported file should contain two notes: IDs 1 and 2 with the exact source texts. A familiar filename with different or missing records is not the desired backup.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Export the intended scope

Choose the data deliberately and keep the archive and credentials private.

Follow START-HERE.txt to prepare two disposable databases. Run seed.sql only in the source, then export.sh with its private connection URL. The custom archive contains the named table; the contents list lets you inspect that scope.

The scripts use no-owner/no-privileges for portability. They do not recreate account roles or a production permission model. Keep archives private because they may contain sensitive data in a real application, and use compatible database tools.

Read backups/contents.txt before restoration. For this fixture, look for entries naming TABLE public backup_practice_notes and TABLE DATA public backup_practice_notes, plus its primary-key constraint. Numeric archive IDs and wording vary by tool version. A list containing only another table is not evidence that this table was exported.

Worked example

A checksum can help detect a later file change. It does not prove that the archive contains all required tables or that anyone can restore it.

PostgreSQL: pg_dump · Supabase: database backup scope

Extra implementation exercise

The archive's checksum is valid. What two major questions remain?

Show a worked solution

Was all required data included, and can it be restored correctly into the intended environment? Integrity of a file is different from completeness and recoverability.

  • Asks whether the required scope was included.
  • Requires an actual restore and data/permission checks.

Step 3

Restore into the separate target

Verify the recovered values instead of only an import message.

In “Separate restore target”, choose your downloaded practice-backup.json. Compare every restored ID and text with the still-visible source; the target should now contain the same two notes without changing the source.

Then use the supplied invalid-backup.json example, available through “Download an invalid example”. It should be rejected while leaving the already-restored target intact. You are testing that a bad file cannot replace good restored data.

A concrete example

A successful two-note restore has IDs 1 and 2 on both sides. After the invalid-file attempt, those same target notes should remain; an error followed by an empty target would fail the protection check.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Restore into a separate empty target

Recovery practice should not overwrite the only working copy.

Run restore.sh against the distinct empty target and inspect its printed database identity before confirming. It does not use --clean or DROP; an existing conflicting table should cause failure instead of being silently overwritten.

After restoration, inspect both rows and their exact values. Confirm the source is unchanged. For a real app, also verify indexes, constraints, relationships, roles and access policies; this small exercise intentionally does not claim those broader guarantees.

Worked example

A target with the same table already present is not the empty practice destination this script expects. Investigate rather than adding destructive flags just to silence the error.

PostgreSQL: pg_restore

Extra implementation exercise

Restore fails because the target table already exists. Should you immediately add --clean?

Show a worked solution

No. Confirm you selected the intended disposable empty database. Use a new empty target for this exercise rather than introducing a destructive option without understanding its impact.

  • Checks target identity and intended state first.
  • Avoids destructive overwrite as a troubleshooting shortcut.

Step 4

Repeat with one new record and state the gaps

A backup habit includes retesting a changed dataset.

Choose “Add the third record”; the source gains ID 3, “Restore check: turquoise notebook”. Download a new backup and keep it distinct from the earlier two-note file. Choose “Empty target” before restoring the new file; the source must stay at three notes.

Compare all three restored IDs/texts. Then use recovery-plan.csv to list the extra coverage your real site would need: its actual database, uploaded files, relationships, permissions and provider recovery process. PostgreSQL scripts below are an optional, separate exercise for confirmed disposable databases.

A concrete example

The old file can correctly restore only IDs 1 and 2. To recover the newly added turquoise-notebook record, you need the new three-note export. A successful old-file restore is not proof that the newest data was backed up.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Your assignment: test a new backup and document the gaps

Make recovery freshness and scope visible.

Add a third distinct note to the source, create a new archive and restore it into another empty target. Record its timestamp/hash, known IDs/values and how long restoration took.

Complete the recovery plan for a hypothetical site that also has uploaded images and signed-in users. Identify which provider tools or separate exports would cover those missing parts, and what checks would prove their restoration.

Worked example

A database row pointing to an image does not include the image's object bytes. Both may be necessary for the website to work after a recovery.

The complete reference walkthrough is available in reference/assignment-walkthrough.txt. Compare its steps with your own result; fill the test record from observations in your own project.

Extra implementation exercise

Prove the new note restores and write a realistic scope/recovery checklist.

Show a worked solution

Seed the two known rows only in the source practice database. Export the named table, inspect the archive contents for its table/data/constraint entries and retain its hash privately. This export does not include other tables, roles, grants, auth or uploaded file bytes.

Restore into a different empty disposable database after checking its identity. Read ID 1 and the exact note 'Restore check: turquoise notebook', plus ID 2. Verify the source remains unchanged. A table-already-exists error is a reason to use another empty target, not to add destructive cleanup flags.

Add ID 3 with a new distinctive note, make a new archive and restore into another fresh target. Check all three exact rows. Complete the separate recovery plan for missing uploads/auth/permissions; do not claim that this one-table exercise recovered those systems.

  • New data is read from a distinct restored target.
  • Missing files, auth and permissions are explicitly accounted for.

Was this lesson useful?

Leave a like, or share it with someone who could use it.

Continue learning

Explore the other lessons