Sebastian Wozny
Sebastian Wozny

Reputation: 17506

Cyclic backups of a docker postgresql container

I would like to deploy an application using docker and would like to use a postgresql container to hold my data.

However I am worried about losing data, so I need back-ups.

I know I could run a cron job on the host to dump the data out from the container, however this approach is not containerized and when I deploy to a new location, I have to remember to add the cronjob.


What is a good , preferably containerized, approach to implement rotating data backups from a postgresql docker container?

Upvotes: 0

Views: 494

Answers (1)

Andrei Ismail
Andrei Ismail

Reputation: 56

Why not deploy a second container that is linked to the PostgreSQL one that does the backups?

It can contain a crontab within, together with instructions on how to upload the backup to Amazon S3, or some other secure storage in the cloud that will not fail even in case of an atomic war :)

Here's some basic information on linking containers: https://docs.docker.com/userguide/dockerlinks/

You can also use Docker Compose in order to deploy a fleet of containers (at least 2, in your case). If your "backup container" uploads stuff to the cloud, make sure you don't put your secrets (such as AWS keys) into the image at build time. Put them into the container at run-time. Here's more information on managing secrets using Docker.

Upvotes: 2

Related Questions