数据库shell脚本,用于统计并复制到另一台服务器

news/2025/5/21 6:48:09

数据库脚本,用来统计操作,并转移至另一台服务器

#!/bin/bashmysclient1="/usr/local/mysql/bin/mysql -uroot -paohe123456 "mysclient2="/usr/local/mysql/bin/mysqldump -uroot -paohe123456 "record_date=$(date '+%Y-%m-%d')
#指定当天某个时段
day_begin_time=`date '+%Y-%m-%d 11:00:00'`
day_end_time=`date '+%Y-%m-%d 20:59:59'`#取某个时段的时间戳
begin_timestamp=`date -d "$day_begin_time" +%s`
end_timestamp=`date -d "$day_end_time" +%s`
timestamp_now=`date +%s`game_type="11200"
#获取当前时间
begin_time=`date '+%Y-%m-%d 00:00:00'`
end_time=`date '+%Y-%m-%d 23:59:59'`#获取昨天时间
yesterday_begin_time=`date -d yesterday '+%Y-%m-%d 00:00:00'`
yesterday_end_time=`date -d yesterday '+%Y-%m-%d 23:59:59'`game_count=`$mysclient1 -e"use log; select sum(x.game_count) as sum_game_countfrom ( select dl.deal_id,max(dl.cur_deal) as game_count from log.tb_open_deal_room_log as rl,log.tb_open_deal_detail_log as dlwhere dl.create_time BETWEEN '$begin_time' and '$end_time'and dl.deal_id=rl.deal_idand rl.game_type='$game_type'group by dl.deal_id) as x; " | sed -n '2p' `# 指定时段内统计昨天的数据
if [ $timestamp_now -ge $begin_timestamp ] && [ $timestamp_now -le $end_timestamp ]
thenyesterday_game_count=`$mysclient1 -e"use log; select sum(x.game_count) as sum_game_countfrom ( select dl.deal_id,max(dl.cur_deal) as game_count from log.tb_open_deal_room_log as rl,log.tb_open_deal_detail_log as dlwhere dl.create_time BETWEEN '$yesterday_begin_time' and '$yesterday_end_time'and dl.deal_id=rl.deal_idand rl.game_type='$game_type'group by dl.deal_id) as x; " | sed -n '2p' `
elseyesterday_game_count="0"
fi$mysclient1 -e"use gamesnapshot; call sp_platform_general_situation_anyminutes_snapshot_3('$record_date','$game_count','$yesterday_game_count');"waring_name=`$mysclient1 -e"use gamesnapshot; select concat('【亲友麻将】','最高在线人数',':',online_top,';','平均在线人数',':',round(avg_online),';','最高在线房间',':',open_top,';','平均在线房间',':',round(avg_open_count)) as waring_name from tb_platform_general_situation_snapshot where record_date='$record_date' and (online_top_rates>=0.2 or open_top_rates>=0.2) and type=1 " | sed -n '2p' `count=`$mysclient1 -e"use game; select count(1) from tb_waring_log where record_date='$record_date'" | sed -n '2p' `if [ $waring_name ] && [ $count -eq 0 ]
then$mysclient1 -e "use game; insert into tb_waring_log (record_date,waring_name,send_time,status,create_time,last_mod_time) values ('$record_date','$waring_name', '0000-00-00 00:00:00', 1,now(), now());"fi#导出表tmp_open_deal_player_room
if [ $timestamp_now -ge $begin_timestamp ] && [ $timestamp_now -le $end_timestamp ]
then$mysclient1 -e"use log; drop table if exists tmp_open_deal_player_room;create table tmp_open_deal_player_room as select a.deal_id,a.player_id,b.need_card_count,b.create_timefrom log.tb_open_deal_player_score_log a,log.tb_open_deal_room_log bwhere a.deal_id=b.deal_id and a.create_time BETWEEN '$yesterday_begin_time' and '$end_time'and b.create_time  BETWEEN '$yesterday_begin_time' and '$end_time'group by a.deal_id,a.player_id;"
else$mysclient1 -e"use log; drop table if exists tmp_open_deal_player_room;create table tmp_open_deal_player_room as select a.deal_id,a.player_id,b.need_card_count,b.create_timefrom log.tb_open_deal_player_score_log a,log.tb_open_deal_room_log bwhere a.deal_id=b.deal_id and a.create_time BETWEEN '$begin_time' and '$end_time'and b.create_time  BETWEEN '$begin_time' and '$end_time'group by a.deal_id,a.player_id;"
fi$mysclient2 log tmp_open_deal_player_room > /scrips/boss_send_message/data/tmp_open_deal_player_room.sqlcd /scrips/boss_send_message/data/$mysclient1 -e"use gamesnapshot; drop table if exists tmp_open_deal_player_room;source tmp_open_deal_player_room.sql;call sp_player_promotion_snapshot('$record_date');call sp_sales_promotion_snapshot('$record_date');"

 

转载于:https://www.cnblogs.com/tangbinghaochi/p/6513360.html

文章来源:https://blog.csdn.net/weixin_30535565/article/details/95985605
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:https://dhexx.cn/news/show-3103545.html

相关文章

微信返回上一页页面参数丢失

做微信公众号开发的时候,遇到一个很纠结的问题。跳转到某些页面之后,用微信自带的返回键返回上一页,会报错,值返回空页面。经检查之后,发现,是在返回过程中,上一页的参数丢失了。 比方说&#x…

【语言-C++】调试运行(在vs)Debug和Release 、以及独立运行Debug无错误,独立运行Release却出现崩溃

断点 经调试出现崩溃的地方为: char* pStrTemp new char[Len] ; 该函数代码如下 char * Topchar(const CString &strSource) { CString STR;int Len strSource.GetLength();STR.Format(_T("%d"),Len);// AfxMessageBox( STR);char* pStrTem…

调用接口Timeout

最近正在对一个旧的项目进行改造。遇到一个问题:调试原有的一个接口时,发现,在本机上,调用接口成功。但是,放到测试环境上之后,调用同一个接口就timeout了。 怀疑是测试环境无法访问接口所在的域名造成的。…

【框架-MFC】调用dll中的对话框

方法一、 dll中代码.h extern "C" __declspec(dllexport) int __stdcall ShowWinCX() ; dll中代码.cpp extern "C" __declspec(dllexport) int __stdcall ShowWinCX() {HINSTANCE save_hInstance AfxGetResourceHandle();//使用自身dll实例中的资源HINST…

jquery文本框内容实时监控

$("#A").bind("input propertychange", function () {$("#B").val($(this).val()); });转载于:https://www.cnblogs.com/lb809663396/p/6519061.html

线性筛欧拉-洛谷P2158 [SDOI2008]仪仗队

https://www.luogu.org/problem/show?pid2158 题目就是求1~n的phi[i]的和 然后*21; 这个找规律即可,我们会发现对于点[x,y]如果(x,y)1那么就可以看见; 这个就是欧拉函数呀; 我们先回顾一下最基本的求1~n的质数的方法&#x…

卸载32位office

安装64位office时,弹出提示,要求卸载32位office。百度了很多方案都卸载不干净。最后找到了一个方案,亲测可行: 运行 regedit,进入到HKEY_CLASSES_ROOT\Installer\Products下,删除0000510开头的项或00002开头项。然后重…

【Windows】Surface - Windows 10 系统截图方法

方法一、组合键 WINdown音量键。 利用按住Windows键同时按下“降低音量”按钮。 默认的保存位置为:C:\Users\\My Pictures\Screenshots 方法二、利用键盘 FNWIN空格键 方法三、利用snipping tool工具 在开始处搜索该工具,界面如下:

前端开发面试题总结之——CSS3

相关知识点 布局、 浮动、 盒子模型、 弹性和模型、 选择器优先级、 居中定位、 兼容性、 hack写法...... 题目&答案 如何理解CSS的盒子模型? 每个HTML元素都是长方形盒子。 (1)盒子模型有两种:IE盒子模型、标准W3C盒子模型&a…

KindEditor上传组件在modal中点击无响应

今天在modal中加上了KindEditor上传组件,组件初始化已成功,但是点击“点击上传附件”按钮无响应,不弹出上传窗口。尝试了百度提供的各种诸如修改z-index值、去掉modal的遮罩层、在弹出modal时初始化上传插件等方案均不生效。最后,…