数据库指定库表中的字段进行备份,并以表格的形式定时发送邮件到指定邮箱
发表于: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安全错误
数据库的锁怎样保障安全
软件开发涉及的法律法规
数据库安全注意事项
mc服务器租用一个月多少钱
小服务器租用
江苏省公安厅网络安全总队杨
开展网络安全监控
android打开数据库
实验三数据管理与数据库
小学生关于网络安全的宣讲
跟网络安全有关的主题
国外服务器搭建梯子网速可以嘛
重返帝国服务器开小差
五莲数据库搜索引擎
西安众信网络技术
军事理论网络安全考试题库
软件开发公司4p
视频监控服务器
网络安全 零风险 零漏洞
gbase登录数据库
小学学习网络安全简报
网络安全实验教程答案
广西网络安全监察
阜阳专业视频系统服务器
网络安全鄙视链
云服务器安全维护流畅运行
淘宝数据库用什么软件
长沙手机软件开发平台
网络安全法二十四
monster租赁服务器
服务器机柜生产投资测算