/ Published in: Bash
Script to backup all MySQL databases and delete copies after X days
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#! /bin/sh # ------------------------------------- # Script to do a full databases backup # and store it X days # # A Navalla Suiza 08/03/2010 # # This script is freely distributed under the GPL # ------------------------------------- # Configuration variables # ------------------------------------- USER='MySQL-USER' PASS='MySQL-PASSWORD' HOST='localhost' BACKUPDIR='/var/backups/mysql' # Script execution # ------------------------------------- data=`date +%Y%m%d` for i in `mysql -u $USER -h $HOST -p$PASS -Bse 'show databases'`; do echo 'Processing '$i mysqldump --add-drop-table -u$USER -p$PASS $i | gzip -9 > $BACKUPDIR/$data-$i.sql.gz done find $BACKUPDIR -type f -mtime +7 -exec rm -f {} \;