[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 {} \;