Skip to content

Instantly share code, notes, and snippets.

@markisatacomputer
Created July 1, 2017 23:20
Show Gist options
  • Save markisatacomputer/04aa2ec3cc557af15279b2ebc7db01e1 to your computer and use it in GitHub Desktop.
Save markisatacomputer/04aa2ec3cc557af15279b2ebc7db01e1 to your computer and use it in GitHub Desktop.
Copy mongo db from local to remote server (container instance with limited memory)
#!/bin/bash
# dump
mongodump -vvv -d hmm-local-beta --gzip --excludeCollection=users --archive=/Path/to/mongo/archive.gz
# old way, container runs out of memory :(
#scp -i ~/.ssh/cert_rsa ~/Path/to/mongo/archive.gz root@[remote host]:/root/import/
##ssh -i ~/.ssh/cert_rsa root@[remote host] "mongorestore -vvv --drop --gzip --stopOnError --archive=/root/import/hmm.gz"
# new way - tunnel - this way we use local memory :)
ssh -fN -l root -i /Users/mnicola/.ssh/cert_rsa -L 9999:localhost:27017 [remote host]
mongorestore -vvv --drop --gzip --stopOnError --port 9999 --archive=/Path/to/mongo/archive.gz
echo "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment