#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin::/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin;
export PATH
export LANG=C
# 系统文件备份路径
basedir=/backup/daily
# 数据库信息
user=root
passwd=t4#*934*#asdgite*
# 定义mysql备份路径
mysql_db_bak=$basedir/mysql_db_bak/$(date +%F_%H%M)
if [ ! -d "$mysql_db_bak" ];
then
mkdir -p $mysql_db_bak
fi
# 定义www备份路径
www_src_bak=$basedir/www_src_bak/$(date +%F_%H%M)
if [ ! -d "$www_src_bak" ];
then
mkdir -p $www_src_bak
fi
# 备份文件
mysql_bak=$mysql_db_bak/wordpress.sql.gz
www_bak=$www_src_bak/www.tar.bz2
# 定义备份文件作为附件的数组
all_bak=($mysql_bak $www_bak)
# 邮件标题
mail_subject="danaotiangong_daily_backup"
# 邮件内容
mail_content_mysql="send MySQL_BAK at $(date +%F_%H%M)"
mail_content_www="send WWW_SRC at $(date +%F_%H%M)"
# 定义内容数组
mail_content=("$mail_content_mysql" "$mail_content_www")
# 邮件地址
mail_address="zhangyao@t4game.com"
# 1. 备份MySQL (数据库目录在/usr/local/mysql)
mysqldump -u $user -p$passwd --opt --skip-lock-tables --flush-logs --database mysql | gzip > $mysql_bak
# 2.备份www源代码:
cd /usr/local
tar -jpcf $www_bak games
# 3.发送附件
yum install mutt -y
for((i=0; i!=${#all_bak[@]}; ++i))
{
echo ${mail_content[i]} | mutt -s $mail_subject $mail_address -a ${all_bak[i]}
}