backup multiple database with mysqldump

From WebHostingNeeds.com
Jump to: navigation, search
mkdir /usr/hostonnet/
vi /usr/hostonnet/backup_mysql.sh

Add

#!/bin/bash

DB_BACKUP="/home/mysql_backup/`date +%Y-%m-%d`"

mkdir -p $DB_BACKUP

find /home/mysql_backup/ -maxdepth 1 -type d -mtime +10 -exec rm -rf {} \;


DATA_BASES=(
    windowwa_blog
    windowwa_booked
    windowwa_copy
    windowwa_db
    windowwa_fab
    windowwa_forum
    windowwa_products
    windowwa_secondhandshop
    windowwa_stats
    windowwa_wordpress
    )

for i in ${DATA_BASES[@]}; do
    /usr/bin/mysqldump ${i} > "$DB_BACKUP/${i}.sql";
done

echo "`date +%Y-%m-%d` mysql backup done /usr/hostonnet/backup_mysql.sh"

Make it executable

chmod 755 /usr/hostonnet/backup_mysql.sh

Create cronjob

0 8 * * * /usr/hostonnet/backup_mysql.sh 2>&1>> /var/log/mysqldump.log



mysql backup