348 views
Linux-shell脚本

备份mysql数据库脚本

Msql常用备份脚本

[code]#!/bin/sh
#backup mysql
#ying 2017-8-10
#Define PATH定义变量
BAK_DIR=/data/backup/mysql/`date +%Y-%m-%d`
MYSQLDB=zabbix
MYSQLPW=backup
MYSQLUSR=backup
#must use root user run scripts 必须使用root用户运行,$UID为系统变量
if
[ $UID -ne 0 ];then
echo This script must use the root user ! ! !
sleep 2
exit 0
fi
#Define DIR and mkdir DIR 判断目录是否存在,不存在则新建
if
[ ! -d $BAK_DIR ];then
mkdir -p $BAK_DIR
fi
#Use mysqldump backup mysql 使用mysqldump备份数据库
/usr/bin/mysqldump -u$MYSQLUSR -p$MYSQLPW -d $MYSQLDB > $BAK_DIR/zabbix_db.sql
TMP=`echo $?`
if
[ $TMP -eq 0 ];then
echo “The mysql backup successfully ”
else
echo “The mysql backup is not successfully ”
fi[/code]

Leave a Reply

影子专属博客 赣ICP备17013143号