From 3c31e4454d29559001ef1e70967fab8e9382bd14 Mon Sep 17 00:00:00 2001 From: yourmoonlight Date: Fri, 29 Apr 2022 11:40:43 +0800 Subject: [PATCH] sync snapshot (#3374) * sync snapshot * 10k blocks to trigger exec sync --- scripts/sync_block.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/sync_block.py b/scripts/sync_block.py index 68b7da890d..d7c925fefe 100644 --- a/scripts/sync_block.py +++ b/scripts/sync_block.py @@ -45,12 +45,12 @@ def check_or_do(network): print("main current_height is %s, last_export_height is %s" % (current_height, last_export_height)) - if int(current_height) - int(last_export_height) > 100000: + if int(current_height) - int(last_export_height) > 10000: # export block, kubectl exec export_tmp = "kubectl exec -it -n starcoin-%s starcoin-1 -- /starcoin/starcoin_db_exporter export-block-range --db-path /sc-data/%s -s %s -e %s -n %s -o /sc-data/." start = last_export_height + 1 - end = last_export_height + 100000 + end = last_export_height + 10000 export_cmd = export_tmp % (network, network, start, end, network) print(export_cmd) os.system(export_cmd) @@ -83,6 +83,20 @@ def check_or_do(network): network, block_list_file_tar_name, network, block_list_file_tar_name) os.system(cp_blocklist_tar_cmd) + # export snapshot + export_snapshot_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- /starcoin/starcoin_db_exporter export-snapshot --db-path /sc-data/%s -n %s -o /sc-data/snapshot -t true" % (network, network, network) + os.system(export_snapshot_cmd) + + # tar snapshot + tar_snapshot_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- tar -czvf /sc-data/%s -C /sc-data/ %s " % ( + network, "snapshot.tar.gz", "snapshot") + os.system(tar_snapshot_cmd) + + # cp snapshot.tar.gz to s3 + cp_snapshot_tar_cmd = "timeout 30 bash -c 'export AWS_REGION=ap-northeast-1;skbn cp --src k8s://starcoin-%s/starcoin-1/starcoin/sc-data/%s --dst s3://main.starcoin.org/%s/%s '" % ( + network, "snapshot.tar.gz", network, "snapshot.tar.gz") + os.system(cp_snapshot_tar_cmd) + # update the last_export_height os.system("echo %s > ./last_export_height.txt" % end) os.system("aws s3api put-object --bucket main.starcoin.org --key %s/last_export_height.txt --body ./last_export_height.txt" % network)