全量备份之分库备份(shell)

mkdir /server/script

cd /server/script

vi mysql_backup_db.sh

#!/bin/sh
mysql_backup_dir=/data/mysql_backup/$(date +%F)
[ ! -d ${mysql_backup_dir} ] &&  mkdir -p ${mysql_backup_dir}
user_pass='-u root -pyeqing '
mysql_login=`mysql ${user_pass} -e "show databases"|sed '1,2d'`
for dbname in ${mysql_login}
do
  mysqldump ${user_pass} -F -B ${dbname}|gzip > ${mysql_backup_dir}/${dbname}_$(date +%F).sql.gz
done

chmod u+x mysql_backup_db.sh

./mysql_backup_db.sh

本文出自 “技术�潘�” 博客,转载请与作者联系!

你可能感兴趣的:(全量备份之分库备份(shell))