Im using meteor-up to deploy to Digital Ocean. All the files have moved across perfectly but I cant figure out how to upload my local database.
Locally I can backup my database with:
mongodump --port=3001 -o “dump folder name”
And import it with:
mongorestore --port=3001 “dump folder name”
Ideally I would import the database from my local file system straight to the server’s database, is this possible?
As I don’t know if this can be done, for now my database is dumped into a folder within my app. When i deploy Im assuming the files are pushed up to the sever with the rest of my app. If I SSH into the server can I run the import and access the database files that way?
Ive tried to follow this thread: Uploading local DB to digital ocean
I tried this from my local:
mongorestore --host MYDOMAIN --port 37017 --username root --password MY-DROPLET-PASSWORD LOCAL-PATH-TO-DB-FOLDER
But got this error:
Failed: error connecting to db server: no reachable servers
I can SSH into my server and then access mongodb with this:
docker exec -it mongodb mongo DB-NAM
But I’m not sure what to do next? When I try and import in a similar way to what worked locally I get an error:
[main] SyntaxError: missing ; before statement @(shell):1:15
Copy the database dump to the droplet and run mongorestore --port=3001 “dump folder name”.
If you’re using github or whatever just do a commit with the database in it and pull it on the droplet.
The database export is a folder called ‘dump’ in my project root, so I think it will get deployed when I run ‘mup deploy’. Is this the same as what you’re saying?
Ive tried that command. First I SSH’d in with ‘ssh root@MY-IP’. When I run ‘mongorestore --port=3001 dump’ I get an error:
2018-01-13T21:36:18.851+0000 warning: Failed to connect to 127.0.0.1:3001, reason: errno:111 Connection refused
couldn’t connect to [127.0.0.1:3001] couldn’t connect to server 127.0.0.1:3001 (127.0.0.1), connection attempt failed
I also tried logging into mongo with ‘docker exec -it mongodb mongo nomad’ and then running ‘mongorestore --port=3001 dump’ and i get the error:
2018-01-13T21:36:53.242+0000 E QUERY [main] SyntaxError: missing ; before statement @(shell):1:15
Im trying a slightly different way. Im assuming that the database files in the Docker image cant be accessed so im uploading them separately.
I sftp into DO with: sftp root@MY-IP
With pdw
I can see that Im in /root
I upload a zip of the database file with put LOCAL-PATH-T0-ZIP
With ls
I can now see the zip file has been uploaded.
Now I need to unzip the file:
I ssh into DO.
I install unzip with: sudo apt-get install unzip
I unzip the file with unzip FILENAME.zip -d NEW-FOLDER
The folder has been created and the database files are inside. So I hope I’m nearly there now, all I need to do is import the uploaded database files into my actual database.
But when I run this:
mongorestore --port=3001 NEW-FOLDER/DB-NAME/
I get an error:
2018-01-14T10:30:59.014+0000 warning: Failed to connect to 127.0.0.1:3001, reason: errno:111 Connection refused couldn't connect to [127.0.0.1:3001] couldn't connect to server 127.0.0.1:3001 (127.0.0.1), connection attempt failed
It would be unusual for a production MongoDB to use port 3001. The normal value is 27107. You can use
netstat -ltp|grep mongod
to confirm the port number the mongod
daemon is listening on.