System Environment: CentOS6.3
Mutt:yum Default Source Installation
1. Install Mutt mail Client
# yum Install Mutt-y
2. Create a script
# vi/etc/rc.d/mail_to_bak_daily.sh
(Version i)
------------------------------------------------------------
#!/bin/bash
# =========================================================
# Please enter which separate directory you want to put the backup data in
Basedir=/backup/daily
# =========================================================
Path=/bin:/usr/bin:/sbin:/usr/sbin::/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin;
Export PATH
Export Lang=c
# define Database Information
User=root
passwd=123456
# define MySQL backup path
mysql_db_bak= $basedir/mysql_db_bak/$ (date +%f_%h%m)
[!-D "$mysql _db_bak"] && mkdir-p $mysql _db_bak
# define WWW backup path
www_src_bak= $basedir/www_src_bak/$ (date +%f_%h%m)
[!-D "$www _src_bak"] && mkdir-p $www _src_bak
# define message attachment path
Mail_attach_mysql= $mysql _db_bak/wordpress.sql
mail_attach_www= $www _src_bak/www.tar.bz2
# define message Headers
mail_subject= "Www.example.com_daily_backup"
# Note: The characters between the headings here can not have spaces, if there are spaces will be issued according to the name of the message, such as daily@www.example.com,backup@www.example.com This example of the following underlined instead
# define message Content
Mail_content=/tmp/mail_content.txt
Mail_code= "Send Mysql_bak and WWW_SRC to/at $ (date +%f_%h%m)"
# define email Addresses
Mail_address= "Test@example.com"
# 1. Backup MySQL (database directory in/usr/local/mysql)
Mysqldump-u $user-p$passwd--opt--skip-lock-tables--flush-logs--database wordpress > $mysql _db_bak/wordpress.sql
# 2. Back up www source code:
Cd/usr/local
tar-jpcf $www _src_bak/www.tar.bz2 www
# 3. Message body
Cd/tmp
echo $mail _code > $mail _content
# 4. Send Attachments
Cat $mail _content |mutt-s $mail _subject-a $mail _attach_mysql-a $mail _attach_www--$mail _address