forked from TaggrNetwork/Taggr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup.sh
executable file
·71 lines (61 loc) · 1.65 KB
/
backup.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
#!/bin/sh
DIR=$1
echo "Using directory $DIR"
CMD=$2
# This script is based on https://forum.dfinity.org/t/canister-backup/11777/26
QU=../qu/target/release/qu
set -e
mkdir -p $DIR
size() {
FILE="$1"
if [[ "$OSTYPE" == "darwin"* ]]; then
stat -f%z $FILE
else
stat -c%s $FILE
fi
}
restore() {
FILE="$1"
echo "Restoring $FILE..."
$QU raw $(cat .dfx/local/canister_ids.json | jq -r ".taggr.local") "stable_mem_write" --args-file "$FILE" | $QU send --yes --raw - > /dev/null
}
if [ "$CMD" == "restore" ]; then
export IC_URL=http://localhost:8080
PAGE=0
while true; do
for _ in {1..10}; do
FILE="$DIR/page$PAGE.bin"
restore $FILE &
PAGE=$((PAGE + 1))
done
wait
if [ "$(size $FILE)" == "18" ]; then break; fi
done
echo "Clearing buckets before restoring heap..."
dfx canister call taggr clear_buckets '("")' || 1
echo "Restoring heap..."
dfx canister call taggr stable_to_heap
echo "Clearing buckets after restoring heap..."
dfx canister call taggr clear_buckets '("")'
echo "Checking consistency..."
dfx canister call taggr check
exit 0
fi
fetch() {
FILE="$1"
$QU raw "6qfxa-ryaaa-aaaai-qbhsq-cai" "stable_mem_read" --args "($PAGE:nat64)" --query |\
$QU send --yes --raw - > $FILE
}
git rev-parse HEAD > $DIR/commit.txt
dfx canister --network ic call taggr backup
PAGE=0
while true; do
for _ in {1..10}; do
FILE="$DIR/page$PAGE.bin"
echo "Fetching page $PAGE..."
fetch $FILE &
PAGE=$((PAGE + 1))
done
wait
if [ "$(size $FILE)" == "18" ]; then break; fi
done