数据库指定库表中的字段进行备份,并以表格的形式定时发送邮件到指定邮箱
发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,备份数据进行定时邮件发送mkdir -p /opt/module/shell/mkdir -p /opt/module/shell/sql/revenue.sqlmkdir -p /opt/modul
千家信息网最后更新 2024年09月22日数据库指定库表中的字段进行备份,并以表格的形式定时发送邮件到指定邮箱
备份数据进行定时邮件发送
mkdir -p /opt/module/shell/mkdir -p /opt/module/shell/sql/revenue.sqlmkdir -p /opt/module/shell/csv/revenue#MailTool.jar 放在指定目录下 便于发送邮件使用 可自动生成表格 vim /opt/module/shell/daily_text.sh# !/bin/bash#数据库指定库.表中的字段进行备份,并以表格的形式发送邮件到指定邮箱#定义变量dat=`date -d '1 days ago' +%Y-%m`basepath=/opt/module/shellsql_revenue=${basepath}/sql/revenue.sqlcsv_revenue=${basepath}/csv/revenue/${dat}.csvfilename=`date +%Y-%m`# html_revenue=${basepath}/html/revenue/${dat}.html#current=`date -d last-day "+%Y-%m-%d"`#timeStamp=`date -d "$current" +%s`# 将current转换为时间戳,精确到毫秒#currentTimeStamp=$((timeStamp*1000))#current2=`date "+%Y-%m-%d"`#time2Stamp=`date -d "$current2" +%s`# 将current转换为时间戳,精确到毫秒#current2TimeStamp=$((time2Stamp*1000))#具体的sql语句 备份某个库里的某个表中的指定字段sql_revenue_total="select date,tb_card_no,goodsId,outItemSKu,money from itoyo_2018.o_jujibao_record Order by date"#数据库的登陆ip,端口,用户,密码mysql=/usr/bin/mysqlhost=数据库ipport=3306username=数据库指定用户名password=密码#将备份的内容导出到定义好的变量文件中$mysql -h$host -P$port -u$username -p$password -e "$sql_revenue_total" > $csv_revenuetotal=`$mysql -h$host -P$port -u$username -p$password -e "$sql_revenue_total" | tail -n+2`echo -e "$total" >> $csv_revenuesed -i 's/\t/","/g' $csv_revenuesed -i 's/^/"/g' $csv_revenuesed -i 's/$/"/g' $csv_revenuesed -i '2,3d' $csv_revenue#过滤出备份文件中当月的信息到指定文件cat $csv_revenue | grep -E "(date|$filename)" |sed '$d' > $csv_revenue.bak#编辑邮件内容及格式confile=${basepath}/conf.propertiesrm -f $confile #这里我用的是腾讯企业邮箱,exmail.qq.com 邮箱端口为465echo "mailhost=smtp.exmail.qq.com" > $confileecho "mailport=465" >> $confileecho "username=邮箱地址" >> $confileecho "password=邮箱密码" >> $confileecho "from=发件人邮箱" >> $confileecho "to=收件人邮箱" >> $confileecho "#cc=" >> $confileecho "#bcc=" >> $confileecho "subject=标题 $dat" >> $confileecho "content=本月数据
#table_revenue#
" >> $confileecho "table_revenue=$csv_revenue.bak" >> $confileecho "file=$csv_revenue.bak" >> $confile#发送邮件 并-mail指定邮件内容 要执行计划任务 必须写绝对路径/data/tools/jdk1.7.0_67/bin/java -jar /opt/module/shell/MailTool.jar -mail $confile
定时计划任务
#该daily_text.sh脚本必须给执行权限crontab -e00 18 30 * * . /opt/module/shell/daily_text.sh
邮箱
数据
邮件
备份
数据库
内容
密码
文件
字段
表格
精确
任务
变量
用户
端口
形式
企业
企业邮箱
信息
发件人
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
西安软件开发解决方案应用
计算机网络技术的行业现状
局长到网络安全大队检查工作
统信系统安装神舟通用数据库
深圳堂石网络技术
电信企业网络安全责任书
企业网络安全管理如何维护
企业网络安全文章绪论
网络技术学习报告
云服务器的5兆是什么意思
3月敏感期网络安全简报
幕义互联网科技
数据库学生表命令
江苏网络安全应急指挥中心
计算机网络技术教师资格证书
郑州人工智能软件开发服务
mysqld进入数据库
软件开发设计公司简介
计算机网络技术容易找工作吗
网络安全信息通报总结
数据库更名操作作用域
csgo国服从服务器
研究所网络安全工程师
浙江运营网络技术市场价格
对日软件开发要会java吗
软件开发设计的优点
软件开发课程海报配色
十一网络技术有限公司
软件开发接项目赚钱吗
软件开发兼职好做么