-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdump.sh
executable file
·51 lines (44 loc) · 1.08 KB
/
dump.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
help () {
echo 'There are 4 available options:'
echo
echo '-h (required) -- host name'
echo '-p -- port'
echo '-d -- database name; if not set - all database will be dumped'
echo '-o -- additional options for mongodump command; wrap in double quotas all the options'
}
if [ $1 == '--help' ]
then
help
exit
fi
host_check=0
while getopts :h:p:f:d:o: option
do
case "${option}"
in
h) HOST=${OPTARG}; host_check=1;;
d) DBNAME=${OPTARG};;
o) OPTIONS=${OPTARG};;
p) PORT=${OPTARG};;
:)
echo "Option $option has to be set"
help
exit
;;
esac
done
if [[ $host_check == 0 ]]
then
echo "-f and -h options must be set"
help
exit
fi
HOST=${HOST:-"localhost"}
PORT=${PORT:-27017}
OPTIONS=${OPTIONS:-""}
if [ -n DBNAME ]
then DB="--db=$DBNAME"
else DB=""
fi
docker run --rm mongo /bin/bash -c "mongodump --host $HOST --port $PORT --archive --gzip $DB $OPTIONS" | \
cat > dump_${DBNAME}_$(date '+%d-%m-%Y_%H-%M-%S').archive