Home >Database >Mysql Tutorial >mysql自动批量备份脚本_MySQL

mysql自动批量备份脚本_MySQL

WBOY
WBOYOriginal
2016-06-01 13:45:071006browse

bitsCN.com

获取数据库名称
#cat datanames.sh
passwd=xxxxxx
mysql mysql --password=$passwd show databases;
EOF
备份脚本
#cat mysql_backup.sh
#获取系统数据库以外的所有数据库名称,存入文本mysql.txt
./datanames.sh |grep -v "Database" | grep -v "ianformation_schema" > mysql.txt
#按日期生成数据库文件夹,数据库中包含备份失败日志
i=`cat mysql.txt`   
nd=`date +%Y%m%d%H`
dt=`date +%Y%m%d%H%M%S`
mkdir $nd
for i in $i
    do
        /usr/bin/mysqldump -pxxxxxx --opt $i >$nd/$nm-$dt.sql 2>$dt/error.txt
done
将mysqldump.sh脚本加入corntab设置为每天或者每周执行一次!即可实现自动备份mysql
1   12  *  *  *   ./root/mysql_backup.sh
作者“xavier”

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn