es增量自定义更新的脚本
安装需要可软件
sudo apt-get install python-pip
sudo pip install elasticsearch;
sudo apt-get install python-dev
sudo pip install MySQL-python
导入脚本import.sh
#!/bin/bash
set -e
bin=/usr/local/elasticsearch-jdbc-1.5.2.0/bin
lib=/usr/local/elasticsearch-jdbc-1.5.2.0/lib
echo '{
"type" : "jdbc",
"jdbc" : {
"url" : "jdbc:mysql://192.168.10.29:3306/db_1",
"user" : "root",
"password" : "root",
"sql" : "select * from '${1}' where dtTime>\"'${2}'\" ",
"index": "db_1",
"type": "'${1}'"
}
}' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter
if [ $? != 0 ];then
exit -1
fi
python调用import.sh实现增量添加:
#!/usr/bin/env python
from datetime import datetime
from elasticsearch import Elasticsearch
import MySQLdb
import time
import os
import subprocess
es=Elasticsearch("192.168.10.29")
def now():
return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
def getLastTime(tableName):
global es
q={
"aggs":
{
"max":{
"max":{"field":"dtTime"}
}
}
}
dt=es.search(index="db_1",doc_type=tableName,body=q)['aggregations']['max']['value']
if dt is None:
return '2015-01-01 00:00:00'
return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(dt/1000))
def insert(tableName,dtLastTime):
global es
print tableName+" startTime:"+str(dtLastTime)
print '/usr/local/elasticsearch-jdbc-1.5.2.0/bin/import.sh %s "%s"'%(tableName,str(dtLastTime))
retCode = subprocess.call('/usr/local/elasticsearch-jdbc-1.5.2.0/bin/import.sh %s "%s"'%(tableName,str(dtLastTime)),shell=True)
if retCode!=0:
print "Import failed"
return
print "%s Import finished"%(now())
es.indices.refresh(index="db_1")
def increment():
conn=MySQLdb.connect(host='192.168.10.29',port=3306,user='root',passwd='root',db ='db_1',)
cur=conn.cursor()
ret=cur.execute('select vTableName,dtLastTime from importinfo')
ret=cur.fetchall()
for line in ret:
tableName=line[0]
fileName=line[1].strftime("%Y-%m-%d-%H-%M-%S")
dtLastTime=getLastTime(tableName)
insert(tableName,dtLastTime)
cur.close()
conn.close()
if __name__=="__main__":
increment()
#getLastTime("achi")
es增量自定义更新的脚本的更多相关文章
- 【Quick 3.3】资源脚本加密及热更新(一)脚本加密
[Quick 3.3]资源脚本加密及热更新(一)脚本加密 注:本文基于Quick-cocos2dx-3.3版本编写 一.脚本加密 quick框架已经封装好加密模块,与加密有关的文件在引擎目录/quic ...
- CodePush自定义更新弹框及下载进度条
CodePush 热更新之自定义更新弹框及下载进度 先来几张弹框效果图 非强制更新场景 image 强制更新场景 image 更新包下载进度效果 image 核心代码 这里的热更新Modal框,是封装 ...
- 自定义nagios监控脚本---磁盘检测
自定义nagios监控脚本---磁盘检测 1. 在客户端上创建脚本/usr/local/nagios/libexec/check_disk.shvim /usr/local/nagios/libexe ...
- 实现将机器A上的程序包复制到机器B并更新的脚本
一.前言 之前有写过如何在单台服务器上执行脚本自动更新程序包,但平时测试过程中相信大部分公司都是需要测试人员在服务器A上进行功能测试,测试通过后再将程序包更新到服务器B上进行安全测试或者性能测试:今天 ...
- Sphinx 增量索引更新
是基于PHP API调用,而不是基于sphinxSE.现在看来sphinxSE比API调用更简单的多,因为之前没有想过sphinxSE,现在先把API的弄明白.涉及到的:sphinx 数据源的设置,简 ...
- Elasticsearch mysql 增量同步 三表联合 脚本
在上一篇中简略的说了一下es同步数据脚本的大致情况,但是实际情况里肯定不会像上一篇里面的脚本那么简单.比如目前我就有三张表,两张实体表,一张关联表.大致实现如下: bin目录建立一个statefile ...
- Zabbix日志监视的汇总报警(更新发送邮件脚本)
Zabbix的用户一定会碰到这种情况: 日志报警一般设置的是multiple模式,有错误大量写入的时候,每写入一行就会触发一次action,导致出现大量的报警邮件. 特别是ora的报警,经常一出就是上 ...
- Unity3D热更新全书-脚本(五) NGUI
让我们实际的研究一下如何将NGUI和C#LightEvil结合起来. 这里使用NGUI2.7,因为他是一个开源的版本,NGUI最新的版本未经作者的许可,是不可以带入我们的开源项目使用的. 这个例子完成 ...
- Unity3D热更新全书-脚本(一) 初识脚本
开篇之前还是要先说明,这是一份给经验并不丰富的程序员阅读的文字. 有需求.有疑惑,往下看. 第一个问题什么是脚本?程序和脚本如何区分?我们给Unity编写的组件是程序还是脚本? 这些问题本文无意去解答 ...
随机推荐
- react相关知识点
1.react内联样式写法: <div style={{width:'200px',height:'100px',border:'1px solid red'}}> </div> ...
- Jfinal基础学习(一)
我负责的项目都是Jfinal的了,有必要写一些学习知识,记录下来. 1.PropKit.use("config.txt", "UTF-8"); PropKit ...
- servlet & filter & listener & interceptor
web.xml 的加载顺序是:context- param -> listener -> filter -> servlet * Servlet 对URL生效,用户处理用户的URL请 ...
- WCF学习心得------(三)配置服务
配置服务 配置服务概述 在设计和实现服务协定后,便可以进行服务的配置.在其中可以定义和自定义如何向客户段公开服务,包括指定可以找到服务的地址,服务用于发送和接受消息的传输和消息编码,以及服务需要的安全 ...
- centos 安装sphinx
官网下载 :http://sphinxsearch.com/downloads/sphinx-2.2.10-release.tar.gz/thankyou.html 安装sphinx 解压 tar z ...
- matlab 画三维图函数
matlab三维绘图 http://blog.sina.com.cn/s/blog_6d5ffd0d0100lyah.html Matlab绘图系列之高级绘图 http://blog.163.com/ ...
- LeetCode "Count of Smaller Number After Self"
Almost identical to LintCode "Count of Smaller Number before Self". Corner case needs to b ...
- Redis容灾部署(哨兵Sentinel)
Redis容灾部署(哨兵Sentinel) 哨兵的作用 1. 监控:监控主从是否正常2. 通知:出现问题时,可以通知相关人员3. 故障迁移:自动主从切换4. 统一的配置管理:连接者询问sentinel ...
- 51nod 1056
n<=10000000000 然后欧拉函数的前缀和可以用莫比乌斯函数的前缀和快速求,注意各种取模 #include<cstdio> typedef long long i64; ,P ...
- php接二进制文件
PHP默认只识别application/x-www.form-urlencoded标准的数据类型. 因此,对型如text/xml 或者 soap 或者 application/octet-stream ...