-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-mongo-db.sh
executable file
·46 lines (36 loc) · 986 Bytes
/
copy-mongo-db.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
#!/bin/sh
echo "Copy mongo DB from remote host into your local mongodb"
echo "Usage: copy-mongo-db.sh [remote db host] [remote db name] [local db name]"
DEFAULT_REMOTE_SERVER="cc1.dev.prv"
DEFAULT_REMOTE_DB="assets_cc1"
DEFAULT_LOCAL_DB="assets_dev"
default() {
if [ "${1}" = "" ] ; then
echo "${2}"
else
echo "${1}"
fi
}
RETURN_VALUE=""
readParam() {
if [ "${3}" = "" ] ; then
read -p "${1}"": ["${2}"] " value
RETURN_VALUE=`default "${value}" "${2}"`
else
echo "${1}: ${3}"
RETURN_VALUE="${3}"
fi
}
echo
echo "*** Remote DB ***"
readParam "host" "${DEFAULT_REMOTE_SERVER}" "${1}"
REMOTE_SERVER=${RETURN_VALUE}
readParam "DB name" "${DEFAULT_REMOTE_DB}" "${2}"
REMOTE_DB=${RETURN_VALUE}
echo
echo "*** Local DB ***"
readParam "DB name" "${DEFAULT_LOCAL_DB}" "${3}"
LOCAL_DB=${RETURN_VALUE}
echo
echo "Restore $REMOTE_DB @ $REMOTE_SERVER into local DB $LOCAL_DB"
mongo --eval "db.copyDatabase('$REMOTE_DB', '$LOCAL_DB', '$REMOTE_SERVER')"