-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
114 lines (86 loc) · 3.57 KB
/
Makefile
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
ifndef SOURCE_PATH
SOURCE_PATH=~/libra
endif
ifndef ARCHIVE_PATH
ARCHIVE_PATH=~/dev-epoch-archive
endif
ifndef DATA_PATH
DATA_PATH=~/.0L
endif
ifndef DB_PATH
DB_PATH=${DATA_PATH}/db
endif
ifndef URL
URL=http://localhost
endif
ifndef EPOCH_LEN
EPOCH_LEN = 1
endif
ifndef TRANS_LEN
TRANS_LEN = 1
endif
END_EPOCH = $(shell expr ${EPOCH} + ${EPOCH_LEN})
EPOCH_WAYPOINT = $(shell jq -r ".waypoints[0]" ${ARCHIVE_PATH}/${EPOCH}/ep*/epoch_ending.manifest)
EPOCH_HEIGHT = $(shell echo ${EPOCH_WAYPOINT} | cut -d ":" -f 1)
check:
@if test -z "$$EPOCH"; then \
echo "Must provide EPOCH in environment" 1>&2; \
exit 1; \
fi
@echo data-path: ${DATA_PATH}
@echo target-db: ${DB_PATH}
@echo backup-service-url: ${URL}
@echo start-epoch: ${EPOCH}
@echo end-epoch: ${END_EPOCH}
@echo epoch-height: ${EPOCH_HEIGHT}
wipe:
sudo rm -rf ${DB_PATH}
create-folder: check
@if test ! -d ${ARCHIVE_PATH}/${EPOCH}; then \
mkdir ${ARCHIVE_PATH}/${EPOCH}; \
fi
bins:
cd ${SOURCE_PATH} && cargo build -p backup-cli --release
sudo cp -f ${SOURCE_PATH}/target/release/db-restore /usr/local/bin/db-restore
sudo cp -f ${SOURCE_PATH}/target/release/db-backup /usr/local/bin/db-backup
commit:
#save to epoch archive repo for testing
git add -A && git commit -a -m "epoch archive ${EPOCH} - ${EPOCH_WAYPOINT}" && git push
zip:
# zip -r ${EPOCH}.zip ${EPOCH}
tar -czvf ${EPOCH}.tar.gz ${EPOCH}
restore-all: wipe restore-epoch restore-transaction restore-snapshot restore-waypoint restore-yaml
# Destructive command. node.yaml, and db will be wiped.
restore-latest:
export EPOCH=$(shell ls | sort -n | tail -1) && make restore-all restore-yaml
backup-all: backup-epoch backup-transaction backup-snapshot
backup-epoch: create-folder
# IMPORTANT: The db-restore tool assumes you are running this from the location of your backups (likely the epoch-archive git project)
# The manifest file includes OS paths to chunks. Those paths are relative and fail if this is run outside of epoch-archive
db-backup one-shot backup --backup-service-address ${URL}:6186 epoch-ending --start-epoch ${EPOCH} --end-epoch ${END_EPOCH} local-fs --dir ${ARCHIVE_PATH}/${EPOCH}
backup-transaction: create-folder
db-backup one-shot backup --backup-service-address ${URL}:6186 transaction --num_transactions ${TRANS_LEN} --start-version ${EPOCH_HEIGHT} local-fs --dir ${ARCHIVE_PATH}/${EPOCH}
backup-snapshot: create-folder
db-backup one-shot backup --backup-service-address ${URL}:6186 state-snapshot --state-version ${EPOCH_HEIGHT} local-fs --dir ${ARCHIVE_PATH}/${EPOCH}
restore-epoch:
db-restore --target-db-dir ${DB_PATH} epoch-ending --epoch-ending-manifest ${ARCHIVE_PATH}/${EPOCH}/epoch_ending_${EPOCH}*/epoch_ending.manifest local-fs --dir ${ARCHIVE_PATH}/${EPOCH}
restore-transaction:
db-restore --target-db-dir ${DB_PATH} transaction --transaction-manifest ${ARCHIVE_PATH}/${EPOCH}/transaction_${EPOCH_HEIGHT}*/transaction.manifest local-fs --dir ${ARCHIVE_PATH}/${EPOCH}
restore-snapshot:
db-restore --target-db-dir ${DB_PATH} state-snapshot --state-manifest ${ARCHIVE_PATH}/${EPOCH}/state_ver_${EPOCH_HEIGHT}*/state.manifest --state-into-version ${EPOCH_HEIGHT} local-fs --dir ${ARCHIVE_PATH}/${EPOCH}
restore-waypoint:
@echo ${EPOCH_WAYPOINT} > ${DATA_PATH}/restore_waypoint
restore-yaml:
@if test ! -d ${DATA_PATH}; then \
mkdir ${DATA_PATH}; \
fi
cp ${ARCHIVE_PATH}/${EPOCH}/fullnode_template.node.yaml ${DATA_PATH}/node.yaml
prod-backup:
URL=http://167.172.248.37 make backup-all
devnet-backup:
rm -rf 1*
EPOCH=1 URL=http://localhost make backup-all zip commit
chron:
#get epoch from key_store.json
#backup-all
#commit changes