-
Notifications
You must be signed in to change notification settings - Fork 4
/
start.sh
executable file
·51 lines (40 loc) · 986 Bytes
/
start.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
#!/bin/bash
MODE=
KEY=
if [ "$1" == "backup" ]; then
MODE='dump'
elif [ "$1" == "restore" ]; then
MODE='restore'
else
>&2 echo "You must provide either backup or restore to run this container"
exit 64
fi
if [ -z "$2" ]; then
KEY=/
else
KEY=$2
fi
if [ "$MODE" == "restore" ]; then
if [ -f "/tmp/dump.json" ]; then
echo "dump.json already provided, skipping download"
else
aws s3 cp s3://$S3_BUCKET/$S3_OBJECT /tmp/dump.json
if [ $? != 0 ]; then
>&2 echo "There was a problem fetching the backup from S3"
exit $?
fi
fi
jq '[.[] | select(.key | startswith("'"$KEY"'"))]' /tmp/dump.json > /tmp/tmp.json
mv /tmp/tmp.json /tmp/dump.json
fi
etcd-dump -h $ETCD_IP -p $ETCD_PORT -f /tmp/dump.json $MODE
if [ $? != 0 ]; then
exit $?
fi
if [ "$MODE" == "dump" ]; then
aws s3 cp /tmp/dump.json s3://$S3_BUCKET/$S3_OBJECT
if [ $? != 0 ]; then
exit $?
fi
fi
exit 0