forked from openbitlab2/near-stakewars-iii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore.sh
89 lines (77 loc) · 1.74 KB
/
restore.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
#!/bin/bash
print_help () {
echo "Usage: ./restore.sh -d /root/.near/data/ -b /root/chall14/backups/near_2022-09-06-14-05/data.tar.gz -s neard.service
-d --data <dir> data directory where to restore
-b --backup <file> backup archive
-s --service <name> service name file"
}
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-b|--backup)
if [[ -z $2 ]]
then
print_help
exit 1
else
backuparchive="$2"
fi
shift # past argument
shift # past value
;;
-d|--data)
if [[ -z $2 ]]
then
print_help
exit 1
else
datadir="$2"
fi
shift # past argument
shift # past value
;;
-s|--service)
if [[ -z $2 ]]
then
print_help
exit 1
else
service="$2"
fi
shift # past argument
;;
-*|--*)
echo "Unknown option $1"
print_help
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
if [[ -z $backuparchive || -z $datadir || -z $service ]]
then
print_help
exit 1
fi
DATE=$(date +%Y-%m-%d-%H-%M)
sudo systemctl stop $service
wait
echo "NEAR node was stopped" | ts
if [ -f "$backuparchive" ]; then
echo "Removing old data folder" | ts
rm -rf $datadir
echo "Removed old data folder" | ts
echo "Restore started" | ts
mkdir $datadir
tar -xf $backuparchive -C $datadir
echo "Restore completed" | ts
else
echo $BACKUPARCHIVE is not created. Check your permissions.
exit 0
fi
sudo systemctl start $service
echo "NEAR node was started" | ts