Thursday, September 22, 2011

MysqlDump with Exclude database or perticuler table Options.

[root@linux_johnson]# cat /usr/bin/imdbbackup
#!/bin/bash
# USER VARIABLES
TIMESTAMP=$(date +%Y-%m-%d)
MYSQLUSER=root
MYSQLPWD=im#secure
MYSQLHOST=localhost
# PATH VARIABLES
MK=/bin/mkdir
GREP=/bin/grep
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
# CREATE MYSQL BACKUP
# Create new backup dir
$MK /backup/mysqlback_$TIMESTAMP
#Dump new files
DBname=db_production


for i in $(echo 'SHOW DATABASES;' | $MYSQL -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST|$GREP -v '^Database$'); do
if [ "$i" == "$DBname" ]; then
             echo " Dump taken"
  mysqldump  -u$MYSQLUSER -p$MYSQLPWD $DBname --ignore-table=db_production.clicks  --ignore-table=db_production.addresses  > /backup/mysqlback_$TIMESTAMP/$i.sql
else
  $MYSQLDUMP -u$MYSQLUSER -p$MYSQLPWD -h$MYSQLHOST $i >/backup/mysqlback_$TIMESTAMP/$i.sql
echo "$i"
fi

done

/etc/init.d/httpd reload




0 comments: