forked from c29r3/cosmos-snapshots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentinel_snapshot.sh
46 lines (33 loc) · 1.26 KB
/
sentinel_snapshot.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
#!/bin/bash
CHAIN_ID="sentinelhub-2"
SNAP_PATH="$HOME/sentinel/sentinel"
LOG_PATH="$HOME/sentinel/sentinel_log.txt"
DATA_PATH="$HOME/.sentinelhub/data/"
SERVICE_NAME="sentinel.service"
RPC_ADDRESS="http://localhost:29657"
SNAP_NAME=$(echo "${CHAIN_ID}_$(date '+%Y-%m-%d').tar")
OLD_SNAP=$(ls ${SNAP_PATH} | egrep -o "${CHAIN_ID}.*tar")
now_date() {
echo -n $(TZ=":Europe/Moscow" date '+%Y-%m-%d_%H:%M:%S')
}
log_this() {
YEL='\033[1;33m' # yellow
NC='\033[0m' # No Color
local logging="$@"
printf "|$(now_date)| $logging\n" | tee -a ${LOG_PATH}
}
LAST_BLOCK_HEIGHT=$(curl -s ${RPC_ADDRESS}/status | jq -r .result.sync_info.latest_block_height)
log_this "LAST_BLOCK_HEIGHT ${LAST_BLOCK_HEIGHT}"
log_this "Stopping ${SERVICE_NAME}"
systemctl stop ${SERVICE_NAME}; echo $? >> ${LOG_PATH}
log_this "Creating new snapshot"
time tar cf ${HOME}/${SNAP_NAME} -C ${DATA_PATH} . &>>${LOG_PATH}
log_this "Starting ${SERVICE_NAME}"
systemctl start ${SERVICE_NAME}; echo $? >> ${LOG_PATH}
log_this "Removing old snapshot(s):"
cd ${SNAP_PATH}
rm -fv ${OLD_SNAP} &>>${LOG_PATH}
log_this "Moving new snapshot to ${SNAP_PATH}"
mv ${HOME}/${CHAIN_ID}*tar ${SNAP_PATH} &>>${LOG_PATH}
du -hs ${SNAP_PATH} | tee -a ${LOG_PATH}
log_this "Done\n---------------------------\n"