shell script to backup mysql databases

Hi,

The following shell script will backup all the individual databases present in your server in .sql format and store it under /mysqlbackup folder. Make sure you have mysql databases in /var/lib/mysql and a folder with name /mysqlbackup. Set a cron to run this script once a day.

#!/bin/bash
#Script for mysql database backup
cd /var/lib/mysql
for DBs in $(ls -d */ |tr -d /)
do

cd /mysqlbackup

`mysqldump -u root -p'password' $DBs > $DBs.sql`

done

Thank you for viewing helpinlinux.com.

Leave a Reply

Protected by WP Anti Spam