mysql備份指令碼
阿新 • • 發佈:2018-12-11
#!/bin/sh
#auto backup mysql
#Define PATH定義變數
BAKDIR=/data/backup/mysql/`date +%Y-%m-%d`
MYSQLDB=webapp
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 $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 "