主要介紹mysql數(shù)據(jù)庫(kù)在linux下的備份操作
以下是shell編碼:
#!/bin/bash
#author lll
dbName=test
fileName=`date +%Y%m%d.%H%M`
backupPath=/root/data
dbuser=root
dbpassword=123456
if [ ! -n "$1" ] ;then
echo -e "---請(qǐng)輸入需要備份數(shù)據(jù)庫(kù)名稱---"
exit
fi
if [ "${dbName}" == "$1" ];then
if [ ! -e $backupPath ];then
echo "---正在創(chuàng)建備份路徑---"
mkdir -p $backupPath
fi
mysqldump -u$dbuser -p$dbpassword $1>$backupPath/$fileName.sql
echo "---$1數(shù)據(jù)庫(kù)備份完成---"
echo "---備份路徑為$backupPath/$fileName.sql---"
else
echo "---please input correct database name---"
exit
fi