yuhongchun/cluster

for DBNAME in mysql test report

Opened this issue · 1 comments

#! /bin/bash
USERNAME=root
PASSWORD=root
DATE=`date +%Y-%m-%d_%H%M%S`
OLDDATE=`date +%Y-%m-%d -d '-20 days'` 
FTPOLDDATE=`date +%Y-%m-%d -d '-60 days'`
MYSQL=/usr/bin/mysql
MYSQLDUMP=/usr/bin/mysqldump
MYSQLADMIN=/usr/bin/mysqladmin
SOCKET=/tmp/mysql.sock
BACKDIR=/data/backup/db

[ -d ${BACKDIR}] || mkdir -p ${BACKDIR}
[ -d ${BACKDIR}/${DATE}] || mkdir ${BACKDIR}/${DATE}
[ ! -d ${BACKDIR}/${OLDDATE}] || rm -rf ${BACKDIR}/${OLDDATE}

for DBNAME in mysql test report
do
	${MYSQLDUMP} --opt -u${USERNAME} -p${PASSWORD} -S${SOCKET} ${DBNAME} | gzip >
		${BACKDIR}/${DATE}/${DBNAME}-backup-${DATE}.sql.gz
	echo "${DBNAME} has been backup successful"
	/bin/sleep 5
done

HOST=121.121.121.121
FTP_USERNAME=ftpusername
FTP_PASSWORD=ftpuserpaswd
cd ${BACKDIR}/${DATE}
ftp -i -n -v << !
open ${HOST}
user ${FTP_USERNAME} ${FTP_PASSWORD}
bin
cd ${FTPOLDDATE}
mdelete *
cd ..
rmdir ${FTPOLDDATE}
mkdir ${DATE}
cd ${DATE}
mput *
bye
!

这段MySQL备份脚本中的这句话不太理解
for DBNAME in mysql test report
DBNAME是固定写法吗?
后面的test是mysql中的数据库名字吗?
另外一个问题
如果我想备份mysql中所有数据库,与你这个脚本如何结合起来使用呢?
我找的脚本类似这种
DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')" for db in $DBS
shell不熟悉,请多多指教