elasticsearch数据迁移python3脚本
#!/usr/bin/python3 #elsearch 数据迁移脚本 #迁移工具路径 import time,os #下面命令是用到了一个go语言写的迁移工具 cmd = "/usr/local/elk/elasticsearch_remove/esm" date = "2017.11" #需要迁移的索引命令,定义一个列表 names = [ "appapi-log", "app-down-log", "mayi-log", "pcwap-analytics-log", "search-info-log", "sslmayi-log", "sslappapi-log", "app-analytics-log", # "m-mayi-log" ] #指定源集群和目标集群 source_host = "http://172.16.17.51:9200" des_host = "http://192.168.40.190:9200" #进行循环索引名称和日期的循环 for name in names: #这里是日期,跟进需要来 for day in range(1,31): a=str(day).zfill(2) exec_cmd = '%s -s %s -d %s -x %s-%s.%s'%(cmd,source_host,des_host,name,date,day) time.sleep(1) try: print('开始执行如下命令:%s',exec_cmd) os.system(exec_cmd) except Exception: print("执行命令错误,请检查") exit(1)