PostgreSQL Backups
Overview
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
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
format
folder
This value should point to the folder on disk that contains the file created by pg_dump
, relative to your data image definition file.
file
This value should contain the file produced by pg_dump
. This file must be present in the folder specified by folder
.
format
This should contain the string plain
to signify the backup format is of type "plain".
Example
An example data image definition file would look like this:
name: PostgresPgDumpPlain
engine: postgresql
version: 11.0
sourceType: backup
backup:
folder: /home/spawn/pgdump/plain/
file: database.dump.sql
format: plain
This will create a PostgreSQL data image called PostgresPgDumpPlain
from a plain pg_dump
backup.
The backup file is located in the /home/spawn/pgdump/plain/
directory, and is called database.dump.sql
.
Custom
Custom backups are restored with the
--no-owner
flag enabled. This means all objects restored will be owned by the auto generated spawn admin user. If you need to, you may change the ownership of objects in subsequent data containers created from this image.
For custom backups, there's some additional configuration required. You'll need to specify the following items in the data image definition file:
folder
file
format
initialDatabaseName
folder
This value should point to the folder on disk that contains the file created by pg_dump
, relative to your data image definition file.
file
This value should contain the file produced by pg_dump
. This file must be present in the folder specified by folder
.
format
This should contain the string custom
to signify the backup format is of type "custom".
initialDatabaseName
This value should contain the name of the database you've backed up through pg_dump
.
Example
An example data image definition file would look like this:
name: PostgresPgDumpCustom
engine: postgresql
version: 11.0
sourceType: backup
backup:
folder: /home/spawn/pgdump/custom/
file: TodoList.dump
format: custom
initialDatabaseName: TodoList
This will create a PostgreSQL data image called PostgresPgDumpCustom
from a custom pg_dump
backup.
The backup file is located in the /home/spawn/pgdump/custom/
directory, and is called TodoList.dump
.
The database dump was generated by invoking pg_dump
on a database called TodoList
. As such, we must also specify the initialDatabaseName
to be TodoList
to ensure the dump can be restored to a database of the same name.