Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync snapshot #3374

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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