DEV Community

Umesh Kumar Dhakar
Umesh Kumar Dhakar

Posted on

4 1

Auto backup of Databases in Postgres Container.

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

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" >> bkp_cmd.sh )

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

4. Append cron file.
crontab -e
00 00 */15 * * /data/bkp_cmd.sh >> /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/bkp_cmd.sh >> /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.

API Trace View

Struggling with slow API calls? 🕒

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (1)

Collapse
 
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}

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay