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

fix sync snapshot scripts and add workflow_dispatch event trigger #3563

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/sync_blocks.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Sync Blocks Cron

on:
# workflow_dispatch:
workflow_dispatch:
schedule:
- cron: '0 5,17 * * *'

Expand Down
2 changes: 1 addition & 1 deletion scripts/dev_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ if [[ "$INSTALL_PROFILE" == "true" ]]; then
fi

install_pkg curl "$PACKAGE_MANAGER"

install_pkg less "$PACKAGE_MANAGER"

if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then
install_build_essentials "$PACKAGE_MANAGER"
Expand Down
19 changes: 10 additions & 9 deletions scripts/sync_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,28 @@ def check_or_do(network):
# check the snapshot is ok or not with the manifest file
# if not, recover the backdir, then exit.
# if ok, rm backup dir, and do the next step
os.system("cp -r /sc-data/snapshot /sc-data/snapshotbak")
os.system(
"kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c 'cp -r /sc-data/snapshot /sc-data/snapshotbak'" % network)
# 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)
export_state_node_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep state_node | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/state_node | wc -l) ]; then exit 0; else exit 1;fi\"")
"kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c \"if [ \$(less /sc-data/snapshot/manifest.csv| grep state_node | awk -F ' ' '{print\$2}') -eq \$(less /sc-data/snapshot/state_node | wc -l) ]; then exit 0; else exit 1;fi\"" % network)
export_acc_node_transaction_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep acc_node_transaction | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/acc_node_transaction | wc -l) ]; then exit 0; else exit 1;fi\"")
"kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c \"if [ \$(less /sc-data/snapshot/manifest.csv| grep acc_node_transaction | awk -F ' ' '{print\$2}') -eq \$(less /sc-data/snapshot/acc_node_transaction | wc -l) ]; then exit 0; else exit 1;fi\"" % network)
export_acc_node_block_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep acc_node_block | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/acc_node_block | wc -l) ]; then exit 0; else exit 1;fi\"")
"kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c \"if [ \$(less /sc-data/snapshot/manifest.csv| grep acc_node_block | awk -F ' ' '{print\$2}') -eq \$(less /sc-data/snapshot/acc_node_block | wc -l) ]; then exit 0; else exit 1;fi\"" % network)
export_block_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep -w block | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/block | wc -l) ]; then exit 0; else exit 1;fi\"")
"kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c \"if [ \$(less /sc-data/snapshot/manifest.csv| grep -w block | awk -F ' ' '{print\$2}') -eq \$(less /sc-data/snapshot/block | wc -l) ]; then exit 0; else exit 1;fi\"" % network)
export_block_info_status = os.system(
"bash -c \"if [ $(less /sc-data/snapshot/manifest.csv| grep block_info | awk -F ' ' '{print$2}') -eq $(less /sc-data/snapshot/block_info | wc -l) ]; then exit 0; else exit 1;fi\"")
"kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c \"if [ \$(less /sc-data/snapshot/manifest.csv| grep block_info | awk -F ' ' '{print\$2}') -eq \$(less /sc-data/snapshot/block_info | wc -l) ]; then exit 0; else exit 1;fi\"" % network)

if export_state_node_status != 0 or export_acc_node_transaction_status != 0 or export_acc_node_block_status != 0 or export_block_status != 0 or export_block_info_status != 0:
os.system("rm -rf /sc-data/snapshot")
os.system("mv /sc-data/snapshotbak /sc-data/snapshot")
os.system("kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c 'rm -rf /sc-data/snapshot'" % network)
os.system("kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c 'mv /sc-data/snapshotbak /sc-data/snapshot'" % network)
sys.exit(1)
os.system("rm -rf /sc-data/snapshotbak")
os.system("kubectl exec -it -n starcoin-%s starcoin-1 -- bash -c 'rm -rf /sc-data/snapshotbak'" % network)

# tar snapshot
tar_snapshot_cmd = "kubectl exec -it -n starcoin-%s starcoin-1 -- tar -czvf /sc-data/%s -C /sc-data/ %s " % (
Expand Down