Skip to content

Cron based drop and restore of a target database with data from a source database

Notifications You must be signed in to change notification settings

CoursePark/postgres-drop-restore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

postgres-drop-restore

Cron based drop and restore of a target database with data from a source database.

Usage

Typically this image is instantiated as a container among many others and would have the responsibility of setting a target database to match that of a source database at a particular time of day.

For instance to have a QC environment get a nightly refresh of data from production.

With a docker-compose set up, this might look like the following:

docker-compose.qc.yml defines a service:

  postgres-drop-restore:
    image: bluedrop360/postgres-drop-restore
    environment:
        CRON_HOUR: 6
        CRON_MINUTE: 0
        SOURCE_DATABASE_URL: postgres://...
        TARGET_DATABASE_URL: postgres://...
    restart: always

At 06:00 UTC the source database is pg_dumped and pg_restored to the target database. This will have some outage time, as long as it takes for DROP DATABASE, CREATE DATABASE, and pg_restore take to process.

Note: the usual cron tricks apply to the hour and minute env values. For instance setting CRON_HOUR to */4 and CRON_MINUTE to 0, will trigger once every 4 hours.

About

Cron based drop and restore of a target database with data from a source database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages