添加DN 迁移脚本及新增环境 test1 用于验证数据迁移
This commit is contained in:
parent
661c8f147c
commit
f96b713d2b
@ -21,6 +21,12 @@ elif myenv == 'test':
|
||||
log_path = "/data/logs/test/"
|
||||
ad_list_interface_port = 6014
|
||||
priv_i_port=6015
|
||||
elif myenv == 'test1':
|
||||
redis_company_config = {'host': '10.10.4.8', 'port': 6379, 'db': 12, 'passwd': 'crs-9ltb97ds:i33dkxshh'}
|
||||
mysql_promotion_config = {'user': 'ad', 'pswd': ad_mysql_pwd, 'host': '10.10.3.5', 'db': 'test1'}
|
||||
log_path = "/data/logs/test/"
|
||||
ad_list_interface_port = 6014
|
||||
priv_i_port=6015
|
||||
else:
|
||||
raise Exception("GET config with mysql/redis failed!")
|
||||
|
||||
|
86
redis/change_db.py
Normal file
86
redis/change_db.py
Normal file
@ -0,0 +1,86 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from mysql.mmysql import MysqlBase
|
||||
import copy
|
||||
import pdb
|
||||
|
||||
old_db = {'user': 'ad', 'pswd': "vF4j56AfxU3P", 'host': '10.10.3.5', 'db': 'ad'}
|
||||
new_db = {'user': 'ad', 'pswd': "vF4j56AfxU3P", 'host': '10.10.3.5', 'db': 'test1'}
|
||||
|
||||
old = MysqlBase(**old_db)
|
||||
new = MysqlBase(**new_db)
|
||||
|
||||
|
||||
def get_old_ad():
|
||||
old_data = []
|
||||
sql = "SELECT id,name,gameid,channelid,locationid,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,jump_param," \
|
||||
"ad_property,ad_sort,jump_status,status,in_used,companyid,createtime FROM `ad` ; "
|
||||
data = old.query(sql)
|
||||
if data:
|
||||
for line in data:
|
||||
if line:
|
||||
temp = {}
|
||||
temp['id'], temp['name'], temp['gameid'], temp['channelid'], temp['locationid'], temp['begin_time'], \
|
||||
temp['end_time'], temp['ad_num'], temp['ad_title'], temp['ad_body'], temp['ad_image'], temp[
|
||||
'jump_param'], temp['ad_property'], temp['ad_sort'], temp['jump_status'], temp['status'], temp[
|
||||
'in_used'], temp['companyid'], temp['createtime'] = line
|
||||
old_data.append(temp)
|
||||
del temp
|
||||
return old_data
|
||||
|
||||
|
||||
def write_ad_data(data):
|
||||
for line in data:
|
||||
table_name = "ad"
|
||||
try:
|
||||
new.insert(table_name, line)
|
||||
except Exception:
|
||||
print(f"write {line} 2 ad failed!")
|
||||
|
||||
|
||||
def get_old_location():
|
||||
location_data = []
|
||||
sql = "SELECT id,area,gameid,channelid,type,mode,in_used,createtime FROM `location` "
|
||||
data = old.query(sql)
|
||||
if data:
|
||||
for line in data:
|
||||
if line:
|
||||
temp = {}
|
||||
temp['id'], temp['area'], temp['gameid'], temp['channelid'], temp['type'], temp['mode'], temp[
|
||||
'in_used'], temp['createtime'] = line
|
||||
temp['ld_property'] = ""
|
||||
try:
|
||||
|
||||
area_old = copy.deepcopy(temp['area'])
|
||||
if len(area_old.split(',')) != 5:
|
||||
print(f"area can`t split {area_old}")
|
||||
else:
|
||||
temp['x'] = area_old.split(',')[1]
|
||||
temp['y'] = area_old.split(',')[2]
|
||||
temp['x_offset'] = area_old.split(',')[3]
|
||||
temp['y_offset'] = area_old.split(',')[4]
|
||||
temp['area'] = f"[{area_old.split(',')[0]}]"
|
||||
location_data.append(temp)
|
||||
del temp
|
||||
except Exception:
|
||||
print(f"split area failed,area={temp['area']} ")
|
||||
return location_data
|
||||
|
||||
|
||||
def write_location(data):
|
||||
for line in data:
|
||||
table_name = "location"
|
||||
try:
|
||||
new.insert(table_name, line)
|
||||
except Exception:
|
||||
print(f"write {line} 2 location failed!")
|
||||
|
||||
|
||||
def main():
|
||||
old_ad = get_old_ad()
|
||||
write_ad_data(old_ad)
|
||||
old_location = get_old_location()
|
||||
write_location(old_location)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user