eventman/docker-tools/run.sh

31 lines
890 B
Bash
Raw Normal View History

2017-11-28 22:24:38 +01:00
#!/bin/sh
if [ $# -lt 1 ] ; then
exit 1
fi
cmd="$1"
2017-11-29 08:59:58 +01:00
if [ "${cmd}" = "--shell" ] ; then
echo "INFO: opening shell..."
mongo --host mongo eventman
elif [ "${cmd}" = "--dump" ] ; then
2017-11-28 22:24:38 +01:00
echo "INFO: dumping..."
2017-11-28 23:00:22 +01:00
mongodump --host mongo --out /tmp/ --db eventman || (echo "ERROR: unable to dump the database" ; exit 10)
2017-11-28 22:24:38 +01:00
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"
2017-11-28 23:00:22 +01:00
exit 20
2017-11-28 22:24:38 +01:00
fi
echo "INFO: restoring $2..."
2017-11-28 23:00:22 +01:00
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)
2017-11-28 22:24:38 +01:00
mongorestore --host mongo -d eventman /tmp/eventman
else
echo "ERROR: command not recognized: use --dump or --restore dumps/file.tgz"
2017-11-28 23:00:22 +01:00
exit 30
2017-11-28 22:24:38 +01:00
fi