-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
50 lines (42 loc) · 1002 Bytes
/
entrypoint.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
#!/bin/bash
set -e
RESTORE_DIR=/restore
gs_project_id="$GS_PROJECT_ID"
gs_service_client_id="$GS_SERVICE_EMAIL"
# Create boto config file
cat <<EOF > /etc/boto.cfg
[Credentials]
gs_service_client_id = $gs_service_client_id
gs_service_key_file = $RESTORE_DIR/service-account.json
[Boto]
https_validate_certificates = True
[GSUtil]
content_language = en
default_api_version = 2
default_project_id = $gs_project_id
EOF
DB_HOST="$MONGO_HOST"
BUCKET_NAME="$GS_RESTORE_BUCKET"
FILE="$GS_RESTORE_FILE"
if [ -z "$DB_HOST" ]; then
echo "DB_HOST is empty."
exit 1
fi
if [ -z "$BUCKET_NAME" ]; then
echo "BUCKET_NAME is empty."
exit 1
fi
if [ -z "$FILE" ]; then
echo "FILE is empty."
exit 1
fi
mkdir -p $RESTORE_DIR
cd $RESTORE_DIR
GZIP=""
if [[ $FILE =~ \.gz$ ]]; then
GZIP="--gzip"
fi
# pull from GCE
echo "Copying gs://$BUCKET_NAME/$FILE to $RESTORE_DIR/$FILE"
/root/gsutil/gsutil cp gs://$BUCKET_NAME/$FILE $FILE 2>&1
mongorestore --host "$DB_HOST" $GZIP --archive="$FILE"