Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backup a mongodb using a ssh

Tags:

ssh

mongodb

Guys I am trying to backup a database.

First I connect to the server using a ssh tunel, then I execute the following command:

mongodump -d mydatabase -o ~/myfolder

and I get this message:

connected to: 127.0.0.1 Thu Feb 6 18:00:56 DATABASE: mydatabase to /home/backups/myfolder/myfolder

As you can see, the mongodump is creating a folder inside a folder, but inside this folder I don't have any files, no json, no bson file.

Could someone, explain me how to make a backup on my server using ssh and the move the files to my local machine.

Thanks in advance.

like image 942
Jean Avatar asked Feb 06 '14 17:02

Jean


People also ask

Does MongoDB use SSH?

You can either select the Collection name from the drop down or enter it manually in the MongoDB SSH connector. You need your SSH credentials (host, port, username, and password) to pull data from a MongoDB collection through an SSH tunnel.

Which command is used to create backup in MongoDB?

To create backup of database in MongoDB, you should use mongodump command. This command will dump the entire data of your server into the dump directory.

What is the command to create backup and restore the MongoDB?

The Mongodump command dumps a backup of the database into the “. bson” format, and this can be restored by providing the logical statements found in the dump file to the databases. The Mongorestore command is used to restore the dump files created by Mongodump.


1 Answers

this is the command you are looking for. this command will access your server database locally 4321 is a port number which can be any port number in which you run your mongodb server [email protected] and this is your server ip.

ssh -L 4321:localhost:27017 [email protected] -f -N

and after this

mongodump --port 4321

this command will make your mongodb dump.

like image 156
akash gaur Avatar answered Oct 15 '22 03:10

akash gaur