将一下内容复制保存至bkupmysql.sh 文件中(没有的话touch创建下),
具体使用方法参考本站链接:https://94ip.com/post/532.html
具体脚本内容如下:
#!/bin/bash dbuser='root' dbpass='vfkahp2p' DaysAgo=7 mysqlpath='/home/backup/mysql' mysql='/www/wdlinux/mysql/bin/mysql' mysqldump='/www/wdlinux/mysql/bin/mysqldump' exclude_db="^Database$\|^mysql$\|^information_schema$\|^performance_schema$\|^test$" logfile='/root/bkinfo.log' #logfail='/root/bkfail.log' now=`date "+%Y-%m-%d %H:%M:%S"` echo $now test -e $mysqlpath||mkdir -p $mysqlpath db_array=`$mysql -u$dbuser -p$dbpass -e"show databases;"|grep -v $exclude_db` if [ $? -eq 0 ];then for dbname in ${db_array[*]} do $mysqldump -f -u$dbuser -p$dbpass $dbname >$mysqlpath/$dbname-$(date +%Y%m%d%H%M%S).sql if [ $? -eq 0 ];then find $mysqlpath -type f -mtime +$[DaysAgo-1] -name "$dbname-*" -exec rm -f {} \; echo $now "sucess $dbname" >> $logfile else echo $now "fail $dbname" >> $logfile fi done else echo $now "All fail" >> $logfile fi
转载请注明:IT运维空间 » Shell » linux下自动备份mysql脚本
继续浏览有关 quotacheck 的文章
发表评论