forked from calr0x/OT-Smoothbrain-Backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestic-backup.sh
executable file
·76 lines (61 loc) · 1.96 KB
/
restic-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
71
72
73
74
75
76
#!/bin/bash
source "/root/OT-Settings/config.sh"
STATUS=$?
N1=$'\n'
if [ -d "/root/backup" ]; then
echo "Deleting existing backup folder"
rm -rf /root/backup
echo "Success!"
fi
ln -s /ot-node/backup /root
cd /ot-node/current
echo "Backing up OT Node data"
OUTPUT=$(node /ot-node/current/scripts/backup.js --config=/ot-node/current/.origintrail_noderc --configDir=/root/.origintrail_noderc/mainnet --backupDirectory=/root/backup 2>&1 | tee /dev/tty )
if [ $? == 1 ]; then
/root/OT-Settings/data/send.sh "OT backup command FAILED:${N1}$OUTPUT"
exit 1
echo "$OUTPUT"
fi
echo "Success!"
echo "Moving data out of dated folder into backup"
OUTPUT=$(mv -v /root/backup/202*/* /root/backup/ 2>&1 | tee /dev/tty)
if [ $? == 1 ]; then
/root/OT-Settings/data/send.sh "Moving data command FAILED::${N1}$OUTPUT"
echo "$OUTPUT"
exit 1
fi
echo "Success!"
echo "Moving hidden data out of dated folder into backup"
OUTPUT=$(mv -v /root/backup/*/.origintrail_noderc /root/backup/ 2>&1 | tee /dev/tty)
if [ $? == 1 ]; then
/root/OT-Settings/data/send.sh "Moving hidden data command FAILED:${N1}$OUTPUT"
echo "$OUTPUT"
exit 1
fi
echo "Success!"
echo "Deleting dated folder"
OUTPUT=$(rm -rf /root/backup/202* 2>&1 | tee /dev/tty)
if [ $? == 1 ]; then
/root/OT-Settings/data/send.sh "Deleting data folder command FAILED:${N1}$OUTPUT"
echo "$OUTPUT"
exit 1
fi
echo "Success!"
echo "Uploading data to Amazon S3"
OUTPUT=$(/root/OT-Smoothbrain-Backup/restic backup /root/backup/.origintrail_noderc /root/backup/* 2>&1 | tee /dev/tty)
if [ $? -eq 0 ]; then
if [ $SMOOTHBRAIN_NOTIFY_ON_SUCCESS == "" ]; then
$SMOOTHBRAIN_NOTIFY_ON_SUCCESS="true"
fi
if [ $SMOOTHBRAIN_NOTIFY_ON_SUCCESS == "true" ]; then
/root/OT-Settings/data/send.sh "Backup SUCCESSFUL:${N1}$OUTPUT"
rm -rf /root/backup/* /root/backup/.origintrail_noderc
fi
else
/root/OT-Settings/data/send.sh "Uploading backup to S3 FAILED:${N1}$OUTPUT"
echo "$OUTPUT"
exit 1
fi
echo $OUTPUT
echo "Success!"
exit 0