1、详细脚本
#!/bin/bash
mysql_cmd=‘-uroot -pRedHat@123’
exclude_db=‘information_schema|performance_schema|sys’
bak_path=/backup/db
mysql m y s q l c m d − e ′ s h o w d a t a b a s e s ′ − N ∣ e g r e p − v " {mysql_cmd} -e 'show databases' -N | egrep -v " mysqlcmd−e′showdatabases′−N∣egrep−v"{exclude_db}" > dbname
while read line
do
[ -d b a k p a t h / {bak_path}/ bakpath/line ] || mkdir -p b a k p a t h / {bak_path}/ bakpath/line
mysqldump ${mysql_cmd} --set-gtid-purged=OFF -B $line | gzip > b a k p a t h / {bak_path}/ bakpath/{line}/KaTeX parse error: Expected group after '_' at position 7: {line}_̲(date +%F).sql.gz
mysql -uroot -pRedHat@123 -N -e “show tables from $line” > tbname
while read tb
do
mysqldump ${mysql_cmd} --set-gtid-purged=OFF $line $tb | gzip > b a k p a t h / {bak_path}/ bakpath/line/KaTeX parse error: Expected group after '_' at position 7: {line}_̲{tb}_$(date +%F).sql.gz
done < tbname
done < dbname
rm -f dbname tbname
2、执行
sh -n back_db_v1.sh
rm -rf /backup/
sh back_db_v1.sh