MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / sync_db_all

Function sync_db_all

script/init_db.py:380–436  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

378
379
380def sync_db_all():
381 num = 0
382 flag_path = '{}/update'.format(dst_dir)
383 if os.path.exists(flag_path):
384 try:
385 num = int(public.readFile(flag_path))
386 except:
387 pass
388 if num > 3:
389 return False
390
391 nlist = []
392 all_tabs = get_database_json(True)
393
394 n_json = {
395 'default.db': default_db_obj,
396 'docker.db': get_data_obj(os.path.join(panelPath, "data/docker.db")),
397 'script.db':get_data_obj(os.path.join(panelPath, "data/crontab.db"))
398 }
399
400 for key in n_json.keys():
401 try:
402 src_db_obj = n_json[key]
403 resp = src_db_obj.query("SELECT name FROM sqlite_master WHERE type='table' AND name not in ('sqlite_sequence','sqlite_master');")
404 if 'unable to open database file' in resp or len(resp) == 0:
405 continue
406
407 for table in resp:
408 try:
409 table = table[0]
410 db_info = {'db': key}
411
412 skey = '{}@{}'.format(table, key)
413 if skey in all_tabs:
414 db_info = all_tabs[skey]
415 elif table in all_tabs:
416 db_info = all_tabs[table]
417
418 print_x('正在同步表到 {} 数据库 - 1:{}'.format(table, db_info['db']))
419 sync_db_table(table, db_info['db'], src_db_obj)
420 nkey = '{}_{}'.format(table, db_info['db'])
421
422 nlist.append(nkey)
423 except:
424 pass
425 except:
426 print_x(public.get_error_info())
427
428 # 第二次检测,防止数据库损坏
429 all_tabs = get_database_json(False)
430 for nkey in all_tabs.keys():
431 db_info = all_tabs[nkey]
432 if not nkey in nlist:
433 print_x('正在同步表到 {} 数据库:{}'.format(db_info['table'], db_info['db']))
434 sync_db_table(db_info['table'], db_info['db'], None)
435
436 public.writeFile(flag_path, str(num + 1))
437

Callers 3

sync_db_tableFunction · 0.85
repair_dbFunction · 0.85
init_db.pyFile · 0.85

Calls 12

get_data_objFunction · 0.85
sync_db_tableFunction · 0.85
readFileMethod · 0.80
writeFileMethod · 0.80
get_database_jsonFunction · 0.70
print_xFunction · 0.70
formatMethod · 0.45
existsMethod · 0.45
joinMethod · 0.45
keysMethod · 0.45
queryMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected