Skip to main content

Backup

Overview#

If you define the sourceType property as backup you will be able to create a data image whose content will be what you defined in your backup.

sourceType: backup
name: dev
engine: mysql
version: 5.7
backup:
folder: mybackup
file: backup.sql

In this case we want to create a MySQL data image whose source is backup and is named dev.

The folder is relative to the location of your yaml file.

Size limit#

Spawn imposes a 500Gi limit on the size of data images.

Tutorial#

As a prerequisite you should've followed the instructions to install spawnctl

Spawn currently supports two formats of PostgreSQL backups:

  • Plain
  • Custom

You can read more about these in the PostgreSQL documentation.

Depending on the type of pg_dump backup you create, your data image definition file will require different configuration.

Plain backups are the default type. If you omit the format value in the data image definition file, Spawn will assume the postgres backup is of the "plain" format.

For plain backups, you'll need to specify the following items in the data image definition file:

  • folder
  • file

Tutorial (video)#

Watch this video for how to create data images from a PostgreSQL database via a backup. Or follow the step-by-step instructions below.

Tutorial (step-by-step)#

Create a backup#

Create a subdirectory for the backup file and data image YAML definition file:

mkdir -p ~/spawn/postgres-backup-image/ && cd ~/spawn/postgres-backup-image/

Assuming there is a database called pagila running at prod-db.example.com on port 5432 and is accessible to the user admin, you can run the following pg_dump command:

pg_dump -h prod-db.example.com -U admin --create pagila > dump.sql

Create a data image yaml file#

Now that we've got a dump.sql file produced by pg_dump we can create our Spawn data image definition YAML file called image.yaml in the current directory with the following contents:

# ~/spawn/postgres-backup-image/image.yaml
sourceType: backup
name: pagila
engine: postgresql
version: 12.0
backup:
folder: /<YOUR_HOME_DIRECTORY>/spawn/postgres-backup-image/
file: dump.sql
tags:
- production

This instructs Spawn to create a data image called pagila on Postgres 12. It will upload the file /<YOUR_HOME_DIRECTORY>/spawn/postgres-backup-image/dump.sql to Spawn and restore that backup using psql, snapshot the state of the restored database and then produce the data image ready for consumption.

The data image will also have a production tag associated with it, so you later know that this data image represents a backup of production.

Create the image#

Run

spawnctl create data-image --file=./image.yaml

This will create the data image from the backup defined in the image.yaml file we created.