-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbrecovery.sh
More file actions
162 lines (121 loc) · 6.5 KB
/
dbrecovery.sh
File metadata and controls
162 lines (121 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
#Args incoming
resetarg=$1
user_name_arg=$2
mainnet_or_testnet=$3
node_folder="coti-node"
#Parameters
if [[ $mainnet_or_testnet == "testnet" ]];
then
restore_hash_param=8eeae832927ed4a95cac73ede5c8b3082e6d3c16c5f98a97d6a7f3fa5b9c8ac364b5e7e8c1cf8d8b09bb23003e4029205d0946d676c6c907d6dccbe35dcbac7b
elif [[ $mainnet_or_testnet == "mainnet" ]];
then
restore_hash_param=8eeae832927ed4a95cac73ede5c8b3082e6d3c16c5f98a97d6a7f3fa5b9c8ac364b5e7e8c1cf8d8b09bb23003e4029205d0946d676c6c907d6dccbe35dcbac7b
fi
restore_source_param=Remote
#If there is an incoming second argument, treat it as a username inserted in, so that we dont need to ask the question.
if [[ $user_name_arg == "" ]];
then
read -p "What is your ubuntu username for coti node? (if unsure write coti, your current username is $(whoami)) : " user_name
else
user_name=$user_name_arg;
fi
config_file="/home/$user_name/$node_folder/fullnode.properties"
function set_config_value(){
#This replaces a key-pair value
paramname=$(printf "%q" $1)
paramvalue=$(printf "%q" $2)
#echo $paramname
#echo $paramvalue
sed -i -E "s/^($paramname[[:blank:]]*=[[:blank:]]*).*/\1$paramvalue/" "$config_file"
}
#----------------------------------------------------------------------------------------------------#
# get_config_value: GLOBAL VALUE IS USED AS A GLOBAL VARIABLE TO RETURN THE RESULT #
#----------------------------------------------------------------------------------------------------#
function get_config_value(){
global_value=$(grep -v '^#' "$config_file" | grep "^$1=" | awk -F '=' '{print $2}')
if [ -z "$global_value" ]
then
return 1
else
return 0
fi
}
reset=""
#DB.RESTORE ####################
# If entry does not exist, create it, otherwise set it to the value on the incoming argument
get_config_value "db.restore"
reset="$global_value"
if [[ $reset == "" ]];
then
echo db.restore=$resetarg >> $config_file
else
set_config_value "db.restore" "$resetarg"
fi
reset=""
#DB.RESTORE.SOURCE ####################
# If entry does not exist, create it, otherwise set it to the value on the restore_source_param parameter at the top of this file
get_config_value "db.restore.source"
reset="$global_value"
if [[ $reset == "" ]];
then
echo db.restore.source=$restore_source_param >> $config_file
else
set_config_value "db.restore.source" "$restore_source_param"
fi
reset=""
#DB.RESTORE.HASH ####################
# If entry does not exist, create it, otherwise set it to the value on the restore_hash_param parameter at the top of this file
get_config_value "db.restore.hash"
reset="$global_value"
if [[ $reset == "" ]];
then
echo db.restore.hash=$restore_hash_param >> $config_file
else
set_config_value "db.restore.hash" "$restore_hash_param"
fi
get_config_value "db.restore"
echo "db.restore is now set to $global_value"
if [[ $global_value == "true" ]];
then
cat << "DB_RESTORE_ON_EOF"
######### Dont be alarmed, just watch for this being set to off later. #########
#
# ██████╗ ██████╗ ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔══██╗██╔══██╗ ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ██║ ██║██████╔╝ ██████╔╝█████╗ ███████╗ ██║ ██║ ██║██████╔╝█████╗
# ██║ ██║██╔══██╗ ██╔══██╗██╔══╝ ╚════██║ ██║ ██║ ██║██╔══██╗██╔══╝
# ██████╔╝██████╔╝ ██║ ██║███████╗███████║ ██║ ╚██████╔╝██║ ██║███████╗
# ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
#
# ██████╗ ███╗ ██╗██╗
# ██╔═══██╗████╗ ██║██║
# ██║ ██║██╔██╗ ██║██║
# ██║ ██║██║╚██╗██║╚═╝
# ╚██████╔╝██║ ╚████║██╗
# ╚═════╝ ╚═╝ ╚═══╝╚═╝
#
###############################################################################
DB_RESTORE_ON_EOF
elif [[ $global_value == "false" ]];
then
cat << "DB_RESTORE_OFF_EOF"
###################### DB is no longer in restore mode :) ######################
#
# ██████╗ ██████╗ ██████╗ ███████╗███████╗████████╗ ██████╗ ██████╗ ███████╗
# ██╔══██╗██╔══██╗ ██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗██╔════╝
# ██║ ██║██████╔╝ ██████╔╝█████╗ ███████╗ ██║ ██║ ██║██████╔╝█████╗
# ██║ ██║██╔══██╗ ██╔══██╗██╔══╝ ╚════██║ ██║ ██║ ██║██╔══██╗██╔══╝
# ██████╔╝██████╔╝ ██║ ██║███████╗███████║ ██║ ╚██████╔╝██║ ██║███████╗
# ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
#
# ██████╗ ███████╗███████╗
# ██╔═══██╗██╔════╝██╔════╝
# ██║ ██║█████╗ █████╗
# ██║ ██║██╔══╝ ██╔══╝
# ╚██████╔╝██║ ██║
# ╚═════╝ ╚═╝ ╚═╝
#
###############################################################################
DB_RESTORE_OFF_EOF
fi