-
Notifications
You must be signed in to change notification settings - Fork 23
/
make_bootstrap.sh
executable file
·121 lines (107 loc) · 4.96 KB
/
make_bootstrap.sh
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
#!/bin/bash
# KMD+AC bootstrap gen (c) Decker, 2019
# --------------------------------------------------------------------------
function init_colors() {
RESET="\033[0m"
BLACK="\033[30m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"
WHITE="\033[37m"
BRIGHT="\033[1m"
DARKGREY="\033[90m"
}
# --------------------------------------------------------------------------
function log_print() {
datetime=$(date '+%Y-%m-%d %H:%M:%S')
echo -e [$datetime] $1
}
# --------------------------------------------------------------------------
function bootstrap() {
if [ ! -z $1 ] && [ $1 != "KMD" ]
then
coin=$1
data_folder=${HOME}/.komodo/$coin
transform='s,^.,'${coin}',S'
else
coin="KMD"
data_folder=${HOME}/.komodo
transform=''
fi
archive_name=bootstrap.${coin,,}.tar.gz
du_files_list="${data_folder}/blocks ${data_folder}/chainstate ${data_folder}/notarisations" # ${data_folder}/komodostate ${data_folder}/komodostate.ind
tar_files_list="./blocks ./chainstate ./notarisations" # ./komodostate ./komodostate.ind
files_size=$(du -cak ${du_files_list} | cut -f1 | tail -1)
checkpoint=$((files_size / 100))
log_print "Archiving \x5B${YELLOW}$i${RESET}\x5D --> ${archive_name}"
log_print "Directory: ${data_folder}"
log_print "Content: ${tar_files_list}"
log_print "Size: ${files_size} Kb, Checkpoint: ${checkpoint} Kb"
# --checkpoint-action=ttyout='[%{%Y-%m-%d %H:%M:%S}t] (%d sec): %u Kb, %T%*\r'
GZIP=-9 tar --directory ${data_folder} \
--record-size=1K --checkpoint="${checkpoint}" --checkpoint-action=ttyout='[%{%Y-%m-%d %H:%M:%S}t] Size: %u Kb, %T Elapsed: %d sec%*\r' \
--show-transformed-names --transform="${transform}" \
--exclude={wallet.dat,*.conf,*.bak,db.log,debug.log,fee_estimates.dat,peers.dat,banlist.dat} \
--exclude={backup_*.dat,.lock,komodod.pid} \
-czvf $(pwd)/${archive_name} ${tar_files_list} > /dev/null
}
# --------------------------------------------------------------------------
function walletbackup_mm() {
# before use read about multiple members with the same name in tar, each time when you will launch
# backup - it will add each wallet.dat as a new member (!), so in .tar you can possible have multiple
# wallet.dat from each coin.
if [ ! -z $1 ] && [ $1 != "KMD" ]
then
coin=$1
data_folder=${HOME}/.komodo/$coin
transform='s,^.,'${coin}',S'
else
coin="KMD"
data_folder=${HOME}/.komodo
transform=''
fi
archive_name=wallets.$(date -u +%Y%m%d).tar # _%H%M%S
tar_files_list="./wallet.dat"
log_print "Backup \x5B${YELLOW}$i${RESET}\x5D wallet.dat --> ${archive_name}"
# https://www.gnu.org/software/tar/manual/html_node/multiple.html#SEC62 - Multiple Members with the Same Name
GZIP=-9 tar --directory ${data_folder} \
--show-transformed-names --transform="${transform}" \
-rvf $(pwd)/${archive_name} ${tar_files_list} # > /dev/null
}
# --------------------------------------------------------------------------
# --- Variables ---
#komodo_cli_binary="$HOME/komodo/src/komodo-cli"
komodo_cli_binary="/home/decker/ssd_nvme/komodo_src_beta/src/komodo-cli"
# -----------------
#
# https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
# https://stackoverflow.com/questions/2264428/how-to-convert-a-string-to-lower-case-in-bash
# https://stackoverflow.com/questions/984204/shell-command-to-tar-directory-excluding-certain-files-folders
# https://stackoverflow.com/questions/18681595/tar-a-directory-but-dont-store-full-absolute-paths-in-the-archive
# https://www.gnu.org/software/tar/manual/html_section/tar_51.html#transform
# https://unix.stackexchange.com/questions/72661/show-sum-of-file-sizes-in-directory-listing
# https://www.gnu.org/software/tar/manual/html_section/tar_26.html#SEC48
# https://stackoverflow.com/questions/1951506/add-a-new-element-to-an-array-without-specifying-the-index-in-bash
# -----------------
init_colors
echo "KMD+AC bootstrap gen (c) Decker, 2019"
echo
log_print "Start making bootstrap for KMD/AC ..."
# https://stackoverflow.com/questions/18669756/bash-how-to-extract-data-from-a-column-in-csv-file-and-put-it-in-an-array
# you can fill coins array from your local assetchains.json file
# readarray -t kmd_coins < <(cat $HOME/komodo/src/assetchains.json | jq -r '[.[].ac_name] | join("\n")')
# or directly from jl777/komodo beta branch assetchains.json
readarray -t kmd_coins < <(curl -s https://raw.githubusercontent.com/KomodoPlatform/dPoW/master/iguana/assetchains.json | jq -r '[.[].ac_name] | join("\n")')
# you can spectify coins array manually if you want
# declare -a kmd_coins=(BEER PIZZA)
kmd_coins+=(KMD)
# printf '%s\n' "${kmd_coins[@]}"
# rm wallets.$(date -u +%Y%m%d).tar
for i in "${kmd_coins[@]}"
do
bootstrap $i
# walletbackup_mm $i
done