bash shell file for daily database backup - Run as CRON job


/ Published in: Bash
Save to your folder(s)

Creates a daily backup and deletes any backup older than 60 days.
Replace:
*DB_USER
*DB_PASSWORD
*DB_NAME
*/path/to/backup
with your actual database name, credentials and path to where you want your backup to live.

Last note: you don't necessarily need to wrap your password in quotes. Some characters will cause it to break without them, however.


Copy this code and paste it in your HTML
  1. #/bin/bash
  2. /usr/bin/mysqldump --user=DB_USER --password='DB_PASSWORD' --databases DB_NAME | gzip > /path/to/backup/DB_NAME-`date +%Y%m%d%H%M`.sql.gz
  3. find /path/to/backup -name "*.gz" -mtime +60 -exec /bin/rm {} \;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.