drop database before a restore

This commit is contained in:
Davide Alberani 2017-11-28 23:00:22 +01:00
parent 149960c1fd
commit 2e822bde24
2 changed files with 6 additions and 4 deletions

View file

@ -4,6 +4,7 @@ LABEL \
vendor="RaspiBO"
EXPOSE 5242
VOLUME ["/eventman/data"]
RUN \
apt-get update && \

View file

@ -8,19 +8,20 @@ cmd="$1"
if [ "${cmd}" = "--dump" ] ; then
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
tar cfz /data/eventman-dump-`date +'%Y-%m-%dT%H:%M:%S'`.tgz eventman
elif [ "${cmd}" = "--restore" ] ; then
if [ -z "$2" ] ; then
echo "ERROR: missing argument to --restore"
exit 2
exit 20
fi
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
else
echo "ERROR: command not recognized: use --dump or --restore dumps/file.tgz"
exit 3
exit 30
fi