跳过正文
  1. Posts/

Mysql数据库备份脚本

·78 字·1 分钟·
Kubehan
作者
Kubehan
云原生知识栈:深度解析容器技术、Kubernetes、Istio、DevOps 实践、Prometheus 监控、Envoy 代理、Golang 开发及云原生架构与微服务趋势的专业博客
[root@Learndb backup_mariadb]# cat dbname 
ask-bar
assets
canvas
cloud-center
course-study
course-ware
custom
dashboard
#!/bin/bash -x
user=root
userPWD='dreamtec20'
mysqlPort=3306
host=192.168.1.1
mysqlHome=/app/mariadb
mysqlBinDir=$mysqlHome/bin
DATE=`date +%Y%m%d`
month=`date +%y%m`
bakDir=/app/backup_mariadb/${DATE}/Full-Backup/
mkdir -p $bakDir

cd $bakDir
DumpFile=$DATE.sql
for i in $(cat /app/backup_mariadb/dbname)
do
   $mysqlBinDir/mysqldump --default-character-set=utf8 -u$user -p$userPWD -P$mysqlPort -h$host --quick -B -R $i > Full-$i.sql --single-transaction
   tar cvzf $i.tar.gz Full-$i.sql --remove-files
done
$mysqlBinDir/mysql -u$user -h${host} -p$userPWD -P$mysqlPort otter -e "truncate log_record;"

find ${bakDir} -maxdepth 1 -type d -mtime +10 -exec rm -rf {} \;