centos中mysql备份数据库脚本分享
本文导语: 代码如下:#!/bin/bash#backup mysql data DBDIR=/data/mysqlBACKDIR=/data/bak/mysqlTIME=`date -d "today" +%F`DB=$(ls -p $DBDIR | grep / |tr -d / | grep -Ev 'information_schema|performance_schema|mysql|test')/etc/init.d/mysqld stopif [ -d $BACKDIR ]then echo "OK!"else ...
#!/bin/bash
#backup mysql data
DBDIR=/data/mysql
BACKDIR=/data/bak/mysql
TIME=`date -d "today" +%F`
DB=$(ls -p $DBDIR | grep / |tr -d / | grep -Ev 'information_schema|performance_schema|mysql|test')
/etc/init.d/mysqld stop
if [ -d $BACKDIR ]
then
echo "OK!"
else
mkdir -p $BACKDIR
fi
cd $DBDIR
for i in $DB
do
tar czf $BACKDIR/$i_db_$TIME.tar.gz $i
done
/etc/init.d/mysqld start
find $BACKDIR -name "*.tar.gz" -type f -mtime +15 -exec rm {} ; >/dev/null 2>&1