Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
add option to replicate-db script to run mongorestore from within VM …
Browse files Browse the repository at this point in the history
…against VM's Mongo instance
  • Loading branch information
abersager committed Jul 11, 2013
1 parent cc445a0 commit 7138c15
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions replicate-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ if [ "$(hostname)" == "vm" ]; then
exit 1
fi

if [ $# -ne 2 ]; then
echo "The script requires two arguments"
if [ $# -lt 1 ]; then
echo "The script requires at least one argument."
echo
echo "Replicate backdrop data from a source host to a target host"
echo "Replicate backdrop data from a source host to a target host."
echo
echo "Usage:"
echo " $(basename $0) <user@source_host> <target_host>"
echo " $(basename $0) <user@source_host> [<target_host>]"
echo
echo "Example:"
echo " $(basename $0) youruser@mongo dev.machine"
echo " This will run mongorestore on the host machine against the specified target host"
echo " $(basename $0) youruser@mongo"
echo " This will run mongorestore from within the development VM"
echo

exit 2
Expand All @@ -42,11 +45,17 @@ ssh $SOURCE_HOST "tar czvf ${FILENAME} ${DUMPDIR}"
# scp tar
scp $SOURCE_HOST:~/$FILENAME .

# cleanup preview machine
ssh $SOURCE_HOST "rm -Rf ${FILENAME} ${DUMPDIR}"

# mongorestore
tar xzvf $FILENAME
mongorestore -h $DESTINATION_HOST $DUMPDIR

# cleanup preview machine
rm -Rf $DUMPDIR
ssh $SOURCE_HOST "rm -Rf ${FILENAME} ${DUMPDIR}"
if [ -z "$2" ]; then
VAGRANT_CWD=../development vagrant ssh -c "cd /var/govuk/backdrop && mongorestore ${DUMPDIR}"
else
mongorestore -h $DESTINATION_HOST $DUMPDIR
fi

# cleanup locally
rm -Rf $DUMPDIR

0 comments on commit 7138c15

Please sign in to comment.