数据库备份shell脚本

法一:

#!/bin/bash
[ ! -d /server/backup ] && mkdir /server/backup
mysqldump -u root -A -B >/server/backup/a.sql
[ ! -f /server/backup/a.sql ] && mail -s "bak faile"

 

法二:
 
#!/bin/sh
DATE=$(date +%Y-%d-%m)
DES=/usr/src/mysql_bak
MYSQL_U="root"
MYSQL_P="123456"
MYSQL_H="127.0.0.1"
if [ ! -d "$DES" ];then
mkdir -p "$DES"
fi
DB=$(mysql -u $MYSQL_U -h $MYSQL_H -p$MYSQL_P -Bse 'show databases')
for database in $DB
do
 
if [ ! $database == "information_schema" ];then
mysqldump -u $MYSQL_U -h $MYSQL_H -p$MYSQL_P $database |bzip2> "$DES/${DATE}_mysql.gz"
fi
done

 


 
posted @ 2017-11-05 22:17  西门运维  阅读(357)  评论(0编辑  收藏  举报