run.sh 918 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/sh
  2. if [ $# -lt 1 ] ; then
  3. exit 1
  4. fi
  5. cmd="$1"
  6. if [ "${cmd}" = "--shell" ] ; then
  7. echo "INFO: opening shell..."
  8. mongo --host mongo eventman
  9. elif [ "${cmd}" = "--dump" ] ; then
  10. echo "INFO: dumping..."
  11. mongodump --host mongo --out /tmp/ --db eventman || (echo "ERROR: unable to dump the database" ; exit 10)
  12. cd /tmp
  13. tar cfz /data/eventman-dump-`date +'%Y-%m-%dT%H.%M.%S'`.tgz eventman --force-local
  14. elif [ "${cmd}" = "--restore" ] ; then
  15. if [ -z "$2" ] ; then
  16. echo "ERROR: missing argument to --restore"
  17. exit 20
  18. fi
  19. echo "INFO: restoring $2..."
  20. tar xfz "/data/$2" -C /tmp --force-local || (echo "ERROR: error unpacking file" ; exit 21)
  21. mongo --host mongo eventman --eval "db.dropDatabase()" || (echo "ERROR: error dropping the database" ; exit 22)
  22. mongorestore --host mongo -d eventman /tmp/eventman
  23. else
  24. echo "ERROR: command not recognized: use --dump or --restore dumps/file.tgz"
  25. exit 30
  26. fi