Posted By

nikefido on 04/26/11


Tagged

Shell Bash backup


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

zack


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


 / Published in: Bash
 

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.

  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  

You need to login to post a comment.