首页 > 代码库 > 全量备份之分库备份(shell)

全量备份之分库备份(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)