Back to Cron Helper
Recipedatabasepostgresbackupsql
Automate PostgreSQL Backups Daily
How to schedule a daily PostgreSQL database backup using cron.This cron job uses the `pg_dump` utility to create a consistent backup of your PostgreSQL database. The command creates a new file each day using the date command `$(date +%Y%m%d)` to prevent overwriting previous backups. We recommend running this at midnight when traffic is low to minimize performance impact.
Cron Schedule
Every Day at Midnight
Runs once per day at 00:00 (midnight).0 0 * * *Command to Run
Copy and paste this command into your crontab or automation script
pg_dump -U username dbname > /backups/db_$(date +%Y%m%d).sqlImplementation Examples
Unix/Linux Crontab
0 0 * * * /path/to/script.sh
Python (with schedule library)
schedule.every().day.at("00:00").do(job)Node.js (with node-cron)
cron.schedule('0 0 * * *', () => {
console.log('Running daily at midnight');
});Go (with robfig/cron)
c.AddFunc("0 0 * * *", func() { fmt.Println("Run daily at midnight") })GitHub Actions Workflow
- cron: "0 0 * * *"
Related Cron Recipes
Automate MySQL Backups Daily
databasemysqlbackup
Automate MongoDB Backups Daily
databasemongodbbackup
Automate Redis RDB Snapshots
databaserediscache
PostgreSQL Vacuum Analyze
databasepostgresmaintenance
Rsync Incremental Backup
linuxbackupnetwork