mysql的一個備份指令碼

rainbowbridg發表於2009-10-10

#/bin/sh

#backup database everyday!
yday=`date -d yesterday +%Y%m%d`

mydump="/usr/local/service/mysql-3306/bin/mysqldump "
myuser="mydbbak"
mypass="enbak"
dirname="/root/myadmin"

hip=`ifconfig eth0 | grep "inet addr" | cut -d: -f2 | cut -d" " -f1`
hports=`netstat -lpn|grep mysqld|grep '^tcp'|awk '{print $4}'|awk -F":" '{print $2}'`

for tport in $hports
do
tdirname="${dirname}/${yday}"
mkdir -p $tdirname
bfilename="${tdirname}/${hip}:${tport}-${yday}.sql"
echo "$bfilename"
$mydump -u$myuser -p$mypwd -P$tport --all-databases --flush-logs --master-data=2 --single-transaction --quick >$bfilename
done

exit

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7916042/viewspace-1027721/,如需轉載,請註明出處,否則將追究法律責任。

相關文章