Reputation: 297
I need to run the following 2 commands very often (maybe once a day for example):
docker exec -t my_db pg_dumpall -c -U postgres > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
docker exec -t my_db pg_dumpall -c -U postgres > latest_backup.sql
How would I do that though? The docker container will be deployed to production and I want to take backups of the database. I read up on cron, but I'm not sure if that's the right way to go about this.
Upvotes: 1
Views: 4489
Reputation: 2096
As Sébastien said, Container crontab is suited if you use rancher. Install the stack and add a label 'cron.schedule=* * * * * *' on your service.
If your not using any orchestration tool, mcuadros/ofelia is a nice little container that is able to schedule commands (exec, run) on your existing containers. It also has some nice logging features like email reports or slack messages.
Upvotes: 0
Reputation: 2210
Yes, you can trigger a pg_dump through docker using a cron job but if you are using an Orchestrator it would be preferable to rely on the task schedulers they provide.
See for example for OpenSift : Cron Jobs, for Kubernetes : Cron Jobs, if you're using Rancher : Container crontab, etc.
Upvotes: 1