6

定时备份MySQL数据库到邮箱

 2 years ago
source link: https://fann.im/blog/2010/10/16/scheduled-backup-mysql-database-to-email/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

定时备份MySQL数据库到邮箱

Oct 16, 2010

照网上例子写了个 bash 脚本,自动备份 MySQL 数据库,并通过 mutt 发邮件到邮箱。

先设置 mutt:vim ~/.muttrc

set envelope_from=yes
set [email protected]
set realname="DBBackup"
set use_from=yes

Bash 脚本内容,vim back.sh

#!/bin/bash
date=date +%Y%m%d
mysqldump DBNAME -u USERNAME -pPASSWORD > /backup/$date.sql
tar czPf /backup/$date.tar.gz /backup/$date.sql
mutt -s "DBBackup" [email protected] -a /backup/$date.tar.gz < /backup/mailContent
rm -f /backup/$(date +%Y%m%d -d "5 days ago").sql
rm -f /backup/$(date +%Y%m%d -d "5 days ago").tar.gz

权限修改:chmod +x back.sh

更新 crontab:27 3 * * * root /back/back.sh

Was this page helpful?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK