1
1
#! /bin/bash
2
2
3
3
function usage() {
4
- printf " Usage: bash copy_blockchain_data_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <Node Index> [download|upload]\n"
4
+ printf " Usage: bash copy_blockchain_data_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <Node Index> [download|upload] [<Old Port Number> <New Port Number>] \n"
5
5
printf " Example: bash copy_blockchain_data_gcp.sh spring 0 download\n"
6
- printf " Example: bash copy_blockchain_data_gcp.sh spring 1 upload\n"
6
+ printf " Example: bash copy_blockchain_data_gcp.sh spring 1 upload 8079 8080 \n"
7
7
printf " \n"
8
8
exit
9
9
}
10
10
11
- if [[ $# -lt 3 ]] || [[ $# -gt 3 ]]; then
11
+ if [[ $# != 3 ]] && [[ $# != 5 ]]; then
12
12
usage
13
13
fi
14
14
@@ -22,7 +22,7 @@ if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[
22
22
PROJECT_ID=" testnet-$1 -ground"
23
23
fi
24
24
else
25
- printf " Invalid <Project/ Season> argument: $1 \n"
25
+ printf " Invalid <Season> argument: $1 \n"
26
26
exit
27
27
fi
28
28
printf " \n"
56
56
fi
57
57
printf " COMMAND=$COMMAND \n"
58
58
59
+ if [[ " $COMMAND " = ' download' ]]; then
60
+ if [[ $# != 3 ]]; then
61
+ printf " \n"
62
+ printf " <Old Port Number> and <New Port Number> can be used only with 'upload' command.\n"
63
+ printf " \n"
64
+ usage
65
+ fi
66
+ OLD_PORT=" "
67
+ NEW_PORT=" "
68
+ else
69
+ if [[ $# != 5 ]]; then
70
+ printf " \n"
71
+ printf " <Old Port Number> and <New Port Number> should be specified with 'upload' command.\n"
72
+ printf " \n"
73
+ usage
74
+ fi
75
+ OLD_PORT=" $4 "
76
+ NEW_PORT=" $5 "
77
+ fi
78
+ printf " OLD_PORT=$OLD_PORT \n"
79
+ printf " NEW_PORT=$NEW_PORT \n"
80
+
59
81
# Get confirmation.
60
82
if [[ " $SEASON " = " mainnet" ]]; then
61
83
printf " \n"
@@ -151,7 +173,13 @@ function upload_data() {
151
173
printf " TGZ_CMD=$TGZ_CMD \n\n"
152
174
eval $TGZ_CMD
153
175
154
- # 3. Clean up tgz file for node
176
+ # 3. Change port number directory
177
+ printf " \n\n<<< Changing port number directory for node $node_index >>>\n\n"
178
+ MV_CMD=" gcloud compute ssh $node_target_addr --command 'mv /home/ain_blockchain_data/chains/${OLD_PORT} /home/ain_blockchain_data/chains/${NEW_PORT} ; mv /home/ain_blockchain_data/snapshots/${OLD_PORT} /home/ain_blockchain_data/snapshots/${NEW_PORT} ' --project $PROJECT_ID --zone $node_zone "
179
+ printf " MV_CMD=$MV_CMD \n\n"
180
+ eval $MV_CMD
181
+
182
+ # 4. Clean up tgz file for node
155
183
printf " \n\n<<< Cleaning up tgz file for node $node_index >>>\n\n"
156
184
CLEANUP_CMD=" gcloud compute ssh $node_target_addr --command 'rm ~/ain_blockchain_data.tar.gz' --project $PROJECT_ID --zone $node_zone "
157
185
printf " CLEANUP_CMD=$CLEANUP_CMD \n\n"
0 commit comments