「shell入門」MySQLデータベースのバックアップ設定スクリプト

shellコード下記:
[root@startnews24]# more mysqlfull_startnews24.sh

#!/bin/sh
# Name:mysqlFullBackup.sh
# PS:MySQL DataBase Full Backup.
# Use mysqldump –help get more detail.
scriptsDir=`pwd`
mysqlDir=/var/lib/mysql
user=root
userPWD=Startnews24_mysqlpwd
dataBackupDir=/usr/local/sdc/backup/mysqlbackup
eMailFile=$dataBackupDir/email.txt
eMail=mysqlbackup@arkgame.com
logFile=$dataBackupDir/mysqlbackup.log
DATE=`date -I`
echo “" > $eMailFile
echo $(date +"%y-%m-%d %H:%M:%S")>>$eMailFile
cd $dataBackupDir
dumpFile=mysql_$DATE.sql
GZDumpFile=mysql_$DATE.sql.tar.gz
#mysqldump -u$user -p$userPWD –opt–default-character-set=utf8 –extended-insert=false –triggers -R –hex-blob–all-databases –flush-logs –delete-master-logs –delete-master-logs -x >$dumpFile
mysqldump -u$user -p$userPWD–all-databases > $dumpFile
#if [[ $? == 0 ]]
if [ “$?" = “0" ]
then
tar czf $GZDumpFile $dumpFile >> $eMailFile 2>&1
echo “BackupFileName:$GZDumpFile" >> $eMailFile
echo “DataBaseバックアップ成功!" >> $eMailFile
rm -f $dumpFile
# Delete daily backup files.
# cd $dataBackupDir/daily
# rm -f *
# Delete old backup files(mtime>33).
#$scriptsDir/rmBackup.sh
find $dataBackupDir -type f -mtime +33 -execrm {} \;
# Move Backup Files To Backup Server.
# if (( !$? )); then
# echo “Move Backup Files To Backup Server Success!" >>$eMailFile
# else
# echo “Move Backup Files To Backup Server Fail!" >>$eMailFile
# fi
else
echo “データベースのバックアップ失敗した!">> $emailFile
fi
echo"——————————————————–" >>$logFile
cat $eMailFile >> $logFile
#cat $eMailFile | mail -s “MySQLBackup" $eMail

shellscript

Posted by arkgame