From 6b2d40ad4dc28c7e5a0f6340ef4c6e91f217f667 Mon Sep 17 00:00:00 2001 From: yourmoonlight Date: Tue, 26 Jul 2022 17:40:17 +0800 Subject: [PATCH 1/2] fix sync snapshot scripts and add workflow_dispatch event trigger --- .github/workflows/sync_blocks.yml | 2 +- scripts/sync_block.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/sync_blocks.yml b/.github/workflows/sync_blocks.yml index f689f703a5..f0a4480f04 100644 --- a/.github/workflows/sync_blocks.yml +++ b/.github/workflows/sync_blocks.yml @@ -1,7 +1,7 @@ name: Sync Blocks Cron on: - # workflow_dispatch: + workflow_dispatch: schedule: - cron: '0 5,17 * * *' diff --git a/scripts/sync_block.py b/scripts/sync_block.py index 75d32d6ca6..0e398fec0d 100644 --- a/scripts/sync_block.py +++ b/scripts/sync_block.py @@ -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 " % ( From e59c6690ac7ad3992c53d46ba57395369bd8dc25 Mon Sep 17 00:00:00 2001 From: yourmoonlight Date: Tue, 26 Jul 2022 17:53:11 +0800 Subject: [PATCH 2/2] add install less to dev_setup --- scripts/dev_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dev_setup.sh b/scripts/dev_setup.sh index ff94ecfb4a..f245197ffb 100755 --- a/scripts/dev_setup.sh +++ b/scripts/dev_setup.sh @@ -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"