#數據庫還原
echo $1
echo $2
echo $3mysql
#!/bin/bash
# MYSQLDBUSERNAME是MySQL數據庫的用戶名,可自定義
MYSQLDBUSERNAME=$1
# MYSQLDBPASSWORD是MySQL數據庫的密碼,可自定義
MYSQLDBPASSWORD=$2
# MYSQBASEDIR是MySQL數據庫的安裝目錄,--prefix=$MYSQBASEDIR,可自定義
MYSQBASEDIR=/usr/local/mysql
# MYSQL是mysql命令的絕對路徑,可自定義
MYSQL=$MYSQBASEDIR/bin/mysql
# MYSQLDUMP是mysqldump命令的絕對路徑,可自定義
MYSQLDUMP=$MYSQBASEDIR/bin/mysqldumpsql
# BACKDIR是數據庫備份的存放地址,能夠自定義修改爲遠程地址
BACKDIR=/home/backup/mysql
# 恢復數據選擇的目錄
TODAY=$3數據庫
echo $TODAY
RECOVERYDIR=$BACKDIR/$TODAYbash
# 獲取MySQL中有備份目錄下的備份文件
DBLIST_TMP=`ls -p $RECOVERYDIR`ip
#獲取目錄下的全部文件名稱,保存到一個變量中去
DBLIST=($(echo $DBLIST_TMP))變量
#echo "集合內中元素爲: ${DBLIST[@]}"
# 從數據庫列表中循環取出數據庫名稱,執行備份操做
for recoveryName in ${DBLIST[@]}循環
do
echo $RECOVERYDIR/$recoveryName
gunzip < $RECOVERYDIR/$recoveryName | mysql --user=${MYSQLDBUSERNAME}密碼
--password=${MYSQLDBPASSWORD} 數據
# 檢查執行結果,若是錯誤代碼爲0則輸出成功,不然輸出失敗
[ $? -eq 0 ] && echo "${recoveryName} has been recoveried successful"word
|| echo "${recoveryName} has been recoveried failed" # 等待3s,可自定義 /bin/sleep 3 done