Skip to content

Commit

Permalink
mysql备份
Browse files Browse the repository at this point in the history
  • Loading branch information
ppabc committed Jun 8, 2016
1 parent 98fccd9 commit f718290
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mysql/mysqldump1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
##备份数据库脚本
## http://www.aqzt.com
##email: [email protected]
##robert yu
#MySQL User Information
USERNAME=root
PASSWORD=m111111111111
#Date Format
DATE=`date +%Y%m%d`
#Back directory
DAYS=20
mkdir -p /backup/db-backup/${DATE}
BACKUP_DIR=/backup/db-backup/${DATE}
#MySQL directory
MYSQL_DIR=/usr/bin
#Go to the backup directory
cd ${BACKUP_DIR}
#The first instance of the backup
while read databasename
do
if [ -f ${databasename}_${DATE}.sql ]; then
echo MySQL Database ${databasename} ${DATE} backup file already exists.
else
${MYSQL_DIR}/mysqldump -u${USERNAME} -p${PASSWORD} ${databasename} --default-character-set=utf8 --opt -Q -R --skip-lock-tables > ${databasename}_${DATE}.sql
fi
done < /home/databasename.txt
find /backup/db-backup/ -name "20*" -type d -mtime +22|tee -a /home/del.txt|xargs rm -r 2>>/home/err.txt

##先做SSH无密码认证,SCP传到另外一台备份
/usr/bin/scp -r /backup/db-backup/${DATE} [email protected]:/mybk/db-backup/bak/

##删除旧备份文件
#find /mybk/db-backup/ -name "20*" -type f -mtime +${DAYS} -exec rm {} \;
exit 0

0 comments on commit f718290

Please sign in to comment.