DEV Community


Auto backup of Databases in Postgres Container.

umeshdhakar profile image Umesh Kumar Dhakar ・1 min read

1. Create A file in Container.
touch /path/<file>
(ex. touch /data/

2. Write Backup command to that file.
echo "pg_dumpall -U postgres -f /path/file" >> <file>
(ex. eg. echo "pg_dumpall -U postgres -f
/data/files/backup_date +%Y%m%d.sql" >> )

3. Make file executable.
chmod 777 <file>
(ex. chmod 777 /data/ )

4. Append cron file.
crontab -e
00 00 */15 * * /data/ >> /data/logs/cron_logs.txt 2>&1
You can generate cron command here.
if no editor is installed then
Append command to cron file via
(crontab -l && echo "00 00 */15 * * /data/ >> /data/backup_cron_logs.txt 2>&1") | crontab -

5. Check whether cron service is running or not.
service cron status
If it it is not running, start it by command
service cron start

5. Wait and check the backup file at specified time.

Thanks for reading! 😊
Please leave a comment if you have any suggestions or you have any doubt.

Discussion (1)

Editor guide
mohammedmahers profile image
Muhammed Maher

Thanks for the tips, so basically it's no difference than normal backups without containers, except we have to execute the commands into the container with docker attach {containerid}