自动备份mysql数据库脚本

 #!/bin/sh
 auto backup mysql
 wxj  2019-06-22
 Define PATH定义变量
 BAKDIR=/data/backup/mysql/date +%Y-%m-%d
 MYSQLDB=wangxuejin
 MYSQLPW=wangxuejin
 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 $BAKDIR ];then
    mkdir -p $BAKDIR
 else
    echo This is $BAKDIR exists…. 
 fi
 # Use mysqldump backup mysql 使用mysqldump备份数据库
 /usr/bin/mysqldump -u$MYSQLUSR -p$MYSQLPW -d $MYSQLDB >$BAKDIR/webapp_db.sql
 echo "The mysql backup successfully "

发表评论

登录... 后才能评论