Skip to main content

Getting started: Using data containers

The state of a Spawn data container can easily be saved so that you can

  • undo mistakes
  • return to previous states
  • store the state to make further copies from

Ensure you've completed the Spawn installation guide before going further.

Accidentally delete data from the database#

We're going to pretend to make a mistake with the database, deleting some data that we didn't intend to. Using the connection details, connect to the database using your preferred client and delete all the records from a table:

DELETE FROM public.film_actor;

Reset the database to its original state#

Normally we'd now need to restore the data from a backup, but Spawn allows you return the database to its original state in just a few seconds using the reset data-container command:

spawnctl reset data-container spawn-tutorial

Reconnect to the database and check -- the data we just deleted is restored, undoing the mistake.

Make some changes you'd like to keep#

What if you want to keep changes that you've made, so that a reset will only return to that point? You can save the state of your database at any time using the save data-container command.

Let's add a new table and some data to our database. Use your database client to execute the following:

CREATE TABLE public.crew
crew_id integer NOT NULL,
first_name text COLLATE pg_catalog."default" NOT NULL,
last_name text COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT crew_pkey PRIMARY KEY (crew_id)
INSERT INTO public.crew VALUES (1, 'John', 'Smith');
INSERT INTO public.crew VALUES (2, 'Jane', 'Doe');

Save the new state as a "revision"#

We can save the current state of the database as a new revision. This is the default state that reset will return to. Each time you use the save data-container command it will create a new revision.

spawnctl save data-container spawn-tutorial
Successfully saved data container 'spawn-tutorial'
New revision is 'rev.1'

You can use the load data-container command to return to states other than the current revision.

Store the state to make further copies#

The revisions that we've created only exist for as long as the data container lives -- if we delete the data container the revisions will be lost. To store a revision for later use we need to use the graduate data-container command, creating a persistent data image that can be used to create new data containers.

spawnctl graduate data-container spawn-tutorial --revision rev.1 --name spawn-tutorial-new-table
Successfully graduated data container 'spawn-tutorial' at revision 'rev.1' to a new data-image
New image 'spawn-tutorial-new-table' (97480) available!

The new image appears in the list of available data images:

spawnctl get data-images

This data image includes the new table that we added to our database, and can be used to create new data containers whenever we need them:

spawnctl create data-container --image spawn-tutorial-new-table --lifetime 1h