Backs up all databases, saves the last 4 copies.

!/bin/bash

# modify the following :
export DB_BACKUP=”/home/user/mysql_backup/”
export DB_USER=”root”
export DB_PASSWD=”********”

echo “MySQL_Backup”
echo “———————-”
echo “* Rotating 4 backups…”
rm -rf $DB_BACKUP/04
mv $DB_BACKUP/03 $DB_BACKUP/04
mv $DB_BACKUP/02 $DB_BACKUP/03
mv $DB_BACKUP/01 $DB_BACKUP/02
mkdir $DB_BACKUP/01

echo “* Creating new backup…”
mysqldump –user=$DB_USER –password=$DB_PASSWD –all-databases | bzip2 > $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2
echo “———————-”
echo “Done”
exit 0

Page 1 of 11