#!/bin/bash
# Database credentials
user=“root”
password=“xxx#i”
host=“localhost”
#db_name=“radius”
#
# Other options
backup_path=“/backup/bvision_DB”
date=$(date +“%b-%d-%Y”)
#
# Set default file permissions
umask 177
#
# Lock the database and sleep in background task
mysql –user=$user –password=$password -e “FLUSH TABLES WITH READ LOCK; DO SLEEP(3600);” &
sleep 3
#
# Dump database into SQL file
mysqldump –user=$user –password=$password –host=$host –all-databases | gzip > $backup_path/BV-DB_FULLBK-$date.sql.gz
#
# When finished, kill the previous background task to unlock
kill $! 2>/dev/null
wait $! 2>/dev/null
echo “Finished export, and unlocked !”
###############################################################################