Skip to content

Commit

Permalink
sync snapshot (#3374)
Browse files Browse the repository at this point in the history
* sync snapshot

* 10k blocks to trigger exec sync
  • Loading branch information
yourmoonlight authored Apr 29, 2022
1 parent 040d5f2 commit 3c31e44
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions scripts/sync_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3c31e44

Please sign in to comment.