-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |