Skip to main content

Getting started: Making data images

In the previous exercise we made a new data image by making changes to a Spawn database and then graduating it. We can also create new data images from scratch. Data images can be created from empty databases, from backups and from scripts.

Create a data image from an existing backup#

Data images can also be created directly from backup files. The backup is first uploaded to the Spawn service and restored to a new database, before being used to create our re-usable data image. For a large backup file the initial upload might take some time, but after that new copies can be created in just a few seconds.

We'll use a sample backup file for this example -- it's just a single table with a few rows of data, generated by pg_dump.

Save dump.sql to a local folder (you might need to rename it to dump.sql).

Save the configuration file database-from-backup.yaml alongside the backup file, renaming it if needed.

database-from-backup.yaml
sourceType: backup
name: database-from-backup
engine: postgresql
version: 12.0
backup:
folder: .
file: dump.sql

This configuration file tells Spawn to create a data image from the backup file dump.sql in the current folder, restoring it to PostgreSQL 12.0, and to name the data image database-from-backup

Call create data-image, passing in the path to the configuration file we created:

spawnctl create data-image --file ./database-from-backup.yaml
Data image 'database-from-backup' (10001) created!

This data image can now be used to create multiple database copies, using spawnctl create data-container as before:

spawnctl create data-container --image database-from-backup --lifetime 1h

Connect to this new data container and you'll find the database just as though it was restored from the backup file. Unlike restoring a database backup though, once the data image has been created Spawn will create new copies in seconds, regardless of the size of the backup.

pgAdmin Workbench query

Besides backups, data images can also be created from empty or from scripts. See source configuration for more information about creating data images from different sources.

Next steps#

That's the basics of Spawn covered:

  • Creating disposable copies of databases for development and testing
  • Resetting those database and creating revisions to undo changes
  • Creating your own data images from which to make further database copies

Next learn more about the spawnctl commands