Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQLdump backup and send email

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Overview:

Smtp protocol is used in the document, and QQ Mail is used to send email, in which the client authorization code is when QQ Mail's smtp service is officially opened, so keep in mind!

1. Configure smtp

# Linux

Yum install-y mailx

# modify configuration file

Vi / etc/mail.rc

# append the following at the end and save

Set from=xxxxxxx@qq.com # set Sender set smtp=smtp.qq.com # set external STMP server set smtp-auth-user=xxxxxxx@qq.com # set STMP username set smtp-auth-password=xxxxxxx # client authenticator set smtp-auth=login

# Test

Echo "this is my test mail" | mail-s' mail test' xxxxxxx@qq.com

2. Set up a backup directory

Mkdir-p / home/mysql/data/backup/mysqlchown mysql:mysql / home/mysql/data/backup/mysql

3. Backup script

Cd / home/mysql/data/backup/mysqlchmod + x mysqldump.shvi mysqldump.shangxinxqldump.shangxinxxxxqldump.shangxinxxxxqldump.shangxxxxqldump.shangxxqldump.shangxxqldump.shangxqldump.shangxqldump.shangxxmysqldump.shangxxmysqldump.shangxmysqldump.shangxxmysqldump.shangxmysqldump.shangxqldump. } / $CURRENT_TIME.sql.gzFLAG=$ {BACKUP_PATH} / $CURRENT_TIME.flagLOG=$ {BACKUP_PATH} / $CURRENT_TIME.log/usr/local/mysql/bin/mysqldump-u$ {DB_USER}-p$ {DB_PW}-- socket=/home/mysql/3306/data/mysql.sock-- host=$HOST-B-- all-databases-- master-data=2-- single-transaction | gzip > $FILE_GZ # backup md5sum $FILE_ must be verified with absolute path # here GZ > ${BACKUP_PATH} / $CURRENT_TIME.flagmd5sum-c ${BACKUP_PATH} / $CURRENT_TIME.flag > ${BACKUP_PATH} / $CURRENT_TIME.log# delete backups from 7 days ago "pay attention to writing" cd $BACKUP_PATHfind $BACKUP_PATH-mtime + 7-name "* sql.gz"-exec rm-f {}\ Find $BACKUP_PATH-mtime + 7-name "* .log"-exec rm-f {}\; find $BACKUP_PATH-mtime + 7-name "* .flag"-exec rm-f {}\; # send email echo "MySQL backup result email, the attachment says OK is successful" | mail-s' mysql backup'- a $LOG xxxxxxx@qq.com

4 、 crontabl

Crontab-e # join this script path

* 23 * / bin/sh / home/mysql/data/backup/mysql/mysqldump.sh

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report