Scheduled Restores¶
Restores can run on a Muppy CRON, typically to refresh a development or staging environment every night.
The restore Task¶
mpy_pg_restore, in the script muppy_postgresql_base.scripts.pg_dump, restores a
pg_dump onto a PostgreSQL cluster.
Parameters that matter for automation¶
| Parameter | Description |
|---|---|
source_database_obj |
Restore the latest dump of this database. Use it instead of pg_dump_obj, which pins one specific dump. The two are mutually exclusive. |
force_restore |
Drop and recreate the target database if it already exists. Guarded — see below. |
qualifier_obj |
Qualifier assigned to the restored database once the restore completes. |
pg_cluster_obj |
Optional when the Host runs a single cluster. Required when it runs several. |
source_database_obj is what makes the schedule work: the Task Run stays valid forever because
it names a database, not a dump that gets purged.
Example: refresh a dev environment nightly¶
Goal — restore the latest production backup onto the development environment every night.
Create a Task Run on mpy_pg_restore with:
source_database_obj— the production databasedb_name— the target database name, e.g.myapp_devforce_restore—True, to overwrite yesterday's copyqualifier_obj— thedev(orstaging) qualifier
Then schedule it as described in Scheduled Backups: test with Launch as Job, click Create Cron, and set the recurrence (for example daily at 03:00).
Execution flow¶
mpy_pg_restore(source_database_obj=prod_db, force_restore=True, qualifier_obj=dev_qualifier)
├── Resolve the latest dump of prod_db
├── Check the target database is not 'prod'
├── Download the dump from S3
├── Close connections to the existing database
├── Drop and recreate the database
├── Restore the data
└── Assign the 'dev' qualifier
Guards against overwriting the wrong database¶
force_restore drops a database. Three rules constrain it:
- Production is protected. A database carrying a
prodqualifier can never be overwritten. - A qualifier is required. A database with no qualifier cannot be overwritten, unless you
pass
qualifier_obj— which states which environment you believe you are writing to. - Restore cannot create production.
qualifier_objmay not be aprodqualifier.
One-off restores¶
For a single restore that does not overwrite anything, use the
restore wizard, or leave force_restore at its default.