centos中mysql备份数据库脚本分享
程序员文章站
2023-11-25 13:27:58
复制代码 代码如下:#!/bin/bash#backup mysql data
dbdir=/data/mysqlbackdir=/data/bak/mysqltime=...
复制代码 代码如下:
#!/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