Linux Labs

Web stack / Stage 8 of 9

A dump and a verified restore

Not running Starting usually ~20 s
Leave the lesson

Step 3 of 7 · on a machine · 6 min

Restoring into a separate database

You will take a fresh dump and bring it up where it cannot break anything: in a new, empty database.

A dump is tested by restoring it into a separate database next to the working one. createdb name creates an empty database; your role has the CREATEDB right. Then pg_restore -d name file: the working database takes no part at all.

pg_dump -Fc -d shop -f file captures the database as it is at the moment of the run, even if the application keeps writing. Yesterday's dump knows nothing about today's orders.

In an empty database pg_restore should hit no errors at all: an error means the copy is incomplete. --exit-on-error stops it at the first error, and --single-transaction runs the whole dump as one transaction: on an error nothing is applied.

Note

A dump remembers owners: it contains ALTER TABLE … OWNER TO student. If you restore as another role, add --no-owner: that role becomes the owner of the objects.

Exercise · do it

Take a dump and bring up a copy

In ~/backup, take a fresh dump of the shop database in the custom format into shop-new.dump and restore it into a new database, shop_check. Leave shop alone.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Take a fresh dump of shop not done yet
  • Restore it into a new database, shop_check not done yet

Step goals

0 of 2
  • Take a fresh dump of shop — not done yet
  • Restore it into a new database, shop_check — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Take a fresh dump of shop — not done yet
  • Restore it into a new database, shop_check — not done yet
Loading…