Sometimes we need a automated system which will make the backup of our database server. But some of the Databases are unnecessary for us to make those backup. This script will help you to make backup of your database but you can exclude the database you don’t want to backup.
USERNAME="user" #User Name of your Database who have access to all databases.
PASSWORD="Password" #Password for your db user
LOCALSERVER="localhost" #Db server host name
BACKUPDIRECTORY=/usr/local/backup/mysqld #Backup directory where backup files will store
IGNOREDB="exampledb1|exampledb2|exampledb3" #Put the Db names which you want to ignore for backup
DATABASELIST=`$MYSQL -u $USERNAME -h $LOCALSERVER -p$PASSWORD -e "show databases;" | grep -Ev "(Database|information_schema|$IGNOREDB)"`
for db in $DATABASELIST; do
$MYSQLDUMP -u $USERNAME -h $LOCALSERVER -p$PASSWORD $db | $GZIP -9 > $FILE
Share and Enjoy
Latest posts by Tapas Mishra (see all)
- Working with Docker – II - December 16, 2016
- Working with Docker – I - November 28, 2016
- How to work with Chef using Oracle VirtualBox and Vagrant on a Windows host – Part II - November 30, 2014