Skip to content

Commit

Permalink
fix sync snapshot scripts and add workflow_dispatch event trigger (#3563
Browse files Browse the repository at this point in the history
)

* fix sync snapshot scripts and add workflow_dispatch event trigger

* add install less to dev_setup
  • Loading branch information
yourmoonlight authored Jul 26, 2022
1 parent 5558d0c commit 45bc82a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
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

0 comments on commit 45bc82a

Please sign in to comment.