Created
January 25, 2016 21:15
-
-
Save LouWii/232b4ed1444597d8ed02 to your computer and use it in GitHub Desktop.
Backup a database using Cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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