Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. #!/bin/bash
  2. # __
  3. # _____ ____ _/ |_ ____ ____ _______
  4. # / \ _/ __ \ \ __\_/ __ \ / _ \ \_ __ \
  5. # | Y Y \\ ___/ | | \ ___/ ( <_> ) | | \/
  6. # |__|_| / \___ > |__| \___ > \____/ |__|
  7. # \/ \/ \/
  8. #
  9. # .___
  10. # __| _/ __ __ _____ ______
  11. # / __ | | | \ / \ \____ \
  12. # / /_/ | | | /| Y Y \| |_> >
  13. # \____ | |____/ |__|_| /| __/
  14. # \/ \/ |__|
  15. #
  16. # The meteor.com Hot Dump 2-step
  17. # Dump a mongo db from a live meteor app to a local dump dir.
  18. #
  19. # Splits up the output of:
  20. # meteor mongo $METEOR_DOMAIN --url
  21. # and pushes it into
  22. # mongodump -u $MONGO_USER -h $MONGO_DOMAIN -d $MONGO_DB -p "${MONGO_PASSWORD}"
  23. #
  24. # Doing so by hand is tedious as the password in the url is only valid for 60 seconds.
  25. #
  26. # Requires
  27. # - meteor (tested on 0.5.9)
  28. # - mongodb (tested in 2.4.0)
  29. #
  30. # Usage
  31. # ./meteor-dump.sh goto
  32. #
  33. # If all goes well it'll create a dump folder in the current working directory.
  34. #
  35. # By @olizilla
  36. # On 2013-03-20. Using this script after it's sell by date may void your warranty.
  37. #
  38.  
  39. METEOR_DOMAIN="$1"
  40.  
  41. if [[ "$METEOR_DOMAIN" == "" ]]
  42. then
  43. echo "You need to supply your meteor app name"
  44. echo "e.g. ./meteor-dump.sh app"
  45. exit 1
  46. fi
  47.  
  48. # REGEX ALL THE THINGS.
  49. # Chomps the goodness flakes out of urls like "mongodb://client:pass-word@skybreak.member0.mongolayer.com:27017/goto_meteor_com"
  50. MONGO_URL_REGEX="mongodb:\/\/(.*):(.*)@(.*)\/(.*)"
  51.  
  52. # stupid tmp file as meteor may want to prompt for a password
  53. TMP_FILE="/tmp/meteor-dump.tmp"
  54.  
  55. # Get the mongo url for your meteor app
  56. meteor mongo $METEOR_DOMAIN --url | tee "${TMP_FILE}"
  57.  
  58. MONGO_URL=$(sed '/Password:/d' "${TMP_FILE}")
  59.  
  60. # clean up the temp file
  61. if [[ -f "${TMP_FILE}" ]]
  62. then
  63. rm "${TMP_FILE}"
  64. fi
  65.  
  66. if [[ $MONGO_URL =~ $MONGO_URL_REGEX ]]
  67. then
  68. MONGO_USER="${BASH_REMATCH[1]}"
  69. MONGO_PASSWORD="${BASH_REMATCH[2]}"
  70. MONGO_DOMAIN="${BASH_REMATCH[3]}"
  71. MONGO_DB="${BASH_REMATCH[4]}"
  72.  
  73. #e.g mongodump -u client -h skybreak.member0.mongolayer.com:27017 -d goto_meteor_com -p "guid-style-password"
  74. mongodump -u $MONGO_USER -h $MONGO_DOMAIN -d $MONGO_DB -p "${MONGO_PASSWORD}"
  75. else
  76. echo "Sorry, no dump for you. Couldn't extract your details from the url: ${MONGO_URL}"
  77. exit 1
  78. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement