123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- from .flightDB import flightDB
- import datetime
- from unitls.LogerinTxt import app_logger
- from unitls.StaticDataclass import get_dic
- def postgresql_bakup(bakcup:flightDB,main:flightDB,type):
- print(datetime.datetime.now(), "[主从同步]开始同步数据库")
- logintoken_dic=['id','username','token']
- loginsts_dic=['id','sts']
- logintable_dic=['id',"登录名","密码","权限","使用人"]
- today = datetime.datetime.now().strftime('%Y%m%d')
- yesterday=(datetime.datetime.now() - datetime.timedelta(days=1)).strftime('%Y%m%d')
- tomorrow=(datetime.datetime.now() + datetime.timedelta(days=1)).strftime('%Y%m%d')
- table_colmuns={"peopleschedule%s"%today:get_dic('peopleScheduleLabel'),"peopleschedule%s"%yesterday:get_dic('peopleScheduleLabel'),"peopleschedule%s"%tomorrow:get_dic('peopleScheduleLabel'),
- 'risktable':get_dic('RiskLabel'),'workerinfo':get_dic('workerinfoLabel'),'pglist%s'%today:get_dic('pglistLabel'),'pglist%s'%yesterday:get_dic('pglistLabel'),
- 'logs':get_dic('logsLabel'),'taskauto':get_dic('taskLabel'),'calllist':get_dic('CalllistLabel'),
- 'flightsts%s'%today:get_dic('flightstsLabel'),'flightsts%s'%yesterday:get_dic('flightstsLabel'),
- 'logintoken':logintoken_dic,'loginsts':loginsts_dic,'logintable':logintable_dic}
- if type == 1:
- dbtables=["peopleschedule%s"%today,"peopleschedule%s"%yesterday,"peopleschedule%s"%tomorrow,'risktable',
- 'workerinfo','pglist%s'%today,'pglist%s'%yesterday,'taskauto','calllist',
- 'flightsts%s'%today,'flightsts%s'%yesterday]#logs太大无法同步
- elif type == 2:
- dbtables=['logintable']
- elif type == 3:
- dbtables=['logintoken','loginsts']
- try:
- tablesok=""
- tablenum=0
- for dbtable in dbtables:
- try:
- if type == 1:
- Dic = {}
- primaryKey2 = 'text'
- for key in list(table_colmuns[dbtable])[1:]:
- Dic[key] = 'text'
- main.initTable(dbtable, table_colmuns[dbtable][0], primaryKey2, Dic)
- all_source_data=bakcup.getAlldata(dbtable)
- if len(all_source_data)!=0:
- main.lazydeleteTable(dbtable)
- for row in all_source_data:
- main.lazyInsertData2(dbtable,', '.join(table_colmuns[dbtable]),row)
- main.FunctionCommit()
- tablesok=tablesok+dbtable+"/"
- tablenum+=1
- except Exception as e:
- app_logger.log_error(e)
- continue
- print(datetime.datetime.now(), "[主从同步]完成数据库同步(%s[%s])"%(tablesok,tablenum))
- return "ok"
- except Exception as e:
- app_logger.log_error(e)
- return "fail"
|