for DBNAME in mysql test report
Opened this issue · 1 comments
beamaster commented
#! /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不熟悉,请多多指教
yuhongchun commented
DBNAME是我取的变量名称,这里你可以根据自己的喜好取名就行了。
2017-03-02 9:15 GMT+08:00 beamaster <notifications@github.com>:
… #! /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 reportdo
${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 5done
HOST=121.121.121.121
FTP_USERNAME=ftpusername
FTP_PASSWORD=ftpuserpaswdcd ${BACKDIR}/${DATE}
ftp -i -n -v << !
open ${HOST}
user ${FTP_USERNAME} ${FTP_PASSWORD}
bincd ${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不熟悉,请多多指教
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AK7DzEg_0o88PkZPlLiJlKnTuugojT0_ks5rhhg2gaJpZM4MQbFt>
.
--
Best Regard
*系统架构设计师 余洪春*