drop database before a restore
This commit is contained in:
parent
149960c1fd
commit
2e822bde24
2 changed files with 6 additions and 4 deletions
|
@ -4,6 +4,7 @@ LABEL \
|
||||||
vendor="RaspiBO"
|
vendor="RaspiBO"
|
||||||
|
|
||||||
EXPOSE 5242
|
EXPOSE 5242
|
||||||
|
VOLUME ["/eventman/data"]
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
|
|
|
@ -8,19 +8,20 @@ cmd="$1"
|
||||||
|
|
||||||
if [ "${cmd}" = "--dump" ] ; then
|
if [ "${cmd}" = "--dump" ] ; then
|
||||||
echo "INFO: dumping..."
|
echo "INFO: dumping..."
|
||||||
mongodump --host mongo --out /tmp/ --db eventman
|
mongodump --host mongo --out /tmp/ --db eventman || (echo "ERROR: unable to dump the database" ; exit 10)
|
||||||
cd /tmp
|
cd /tmp
|
||||||
tar cfz /data/eventman-dump-`date +'%Y-%m-%dT%H:%M:%S'`.tgz eventman
|
tar cfz /data/eventman-dump-`date +'%Y-%m-%dT%H:%M:%S'`.tgz eventman
|
||||||
elif [ "${cmd}" = "--restore" ] ; then
|
elif [ "${cmd}" = "--restore" ] ; then
|
||||||
if [ -z "$2" ] ; then
|
if [ -z "$2" ] ; then
|
||||||
echo "ERROR: missing argument to --restore"
|
echo "ERROR: missing argument to --restore"
|
||||||
exit 2
|
exit 20
|
||||||
fi
|
fi
|
||||||
echo "INFO: restoring $2..."
|
echo "INFO: restoring $2..."
|
||||||
tar xfz "/data/$2" -C /tmp
|
tar xfz "/data/$2" -C /tmp || (echo "ERROR: error unpacking file" ; exit 21)
|
||||||
|
mongo --host mongo eventman --eval "db.dropDatabase()" || (echo "ERROR: error dropping the database" ; exit 22)
|
||||||
mongorestore --host mongo -d eventman /tmp/eventman
|
mongorestore --host mongo -d eventman /tmp/eventman
|
||||||
else
|
else
|
||||||
echo "ERROR: command not recognized: use --dump or --restore dumps/file.tgz"
|
echo "ERROR: command not recognized: use --dump or --restore dumps/file.tgz"
|
||||||
exit 3
|
exit 30
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue