Skip to content

Instantly share code, notes, and snippets.

@LouWii LouWii/cron-edit.sh
Created Jan 25, 2016

Embed
What would you like to do?
Backup a database using Cron
# Edit your crontab file using crontab -e command
#
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# backup database at 3am
0 3 * * * pg_dump -U blen blen > /backups/pgsql_backups/blen-export-$(date +\%F).pgsql
# delete 1 week old backups
5 3 * * * find /backups/pgsql_backups -type f -mtime +7 -exec rm {} +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.