Simple mySQL backup script for cron

Valic —  October 11, 2010 — 4 Comments

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

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

4 responses to Simple mySQL backup script for cron

  1. sell this domain at sedo October 14, 2010 at 02:59

    Yes… i also really like to visit this new place, your idea is good.

  2. Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader.

  3. sell this domain at sedo October 16, 2010 at 20:59

    I cannot thank you enough for the blog article.Thanks Again. Will read on…

  4. thanks for the post

Leave a Reply