Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 202 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mongodump from remote server

#1
We recently ported some data over to MongoDB and are now looking into running daily backups, preferably from a cron job, and restore one of the backups to a secondary mongo database.

Our system is set up as follows:

- server 1: the development mongo database
- server 2: two mongo databases, one for staging data and one for production
- server 3: is where we run all of our cron jobs/batch scripts from.

I checked the mongo docs, and logged into our cron job server and tried to run the following command: (username, host, and password changed for security, I'm not actually connecting to localhost)

mongodump --host 127.0.0.1/development --port 27017 --username user --password pass --out /opt/backup/mongodump-2013-10-07-1

I get the following messages:

> Mon Oct 7 10:03:42 starting new replica set monitor for replica set 127.0.0.1 with seed of development:27017
> Mon Oct 7 10:03:42 successfully connected to seed development:27017 for replica set 127.0.0.1
> Mon Oct 7 10:03:42 warning: node: development:27017 isn't a part of set: 127.0.0.1 ismaster: { ismaster: true, maxBsonObjectSize: 16777216, ok: 1.0 }
> Mon Oct 7 10:03:44 replica set monitor for replica set 127.0.0.1 started, address is 127.0.0.1/
> Mon Oct 7 10:03:44 [ReplicaSetMonitorWatcher] starting couldn't connect to [127.0.0.1/development:27017] connect failed to set 127.0.0.1/development:27017

I confirmed that I can connect to the mongo database using `mongo -u -p ip/development`

Our ultimate goal will be to dump the data from the production database and store it in the staging database. These two databases are both located on the same box, if that makes a difference, but for testing purposes I am just trying to get a backup of development test data.
Reply

#2
`mongo` client can parse [MongoDB connection string URI](

[To see links please register here]

), so instead of specifying all connection parameters separately you may pass single connection string URI.

In your case you're trying to pass connection URI as a `host`, but `127.0.0.1/development` is not a valid host name. It means you should specify `database` parameter separately from the `host`:

mongodump --host 127.0.0.1 -d development --port 27017 --username user --password pass --out /opt/backup/mongodump-2013-10-07-1
Reply

#3
mongodump --host remotehostip:port --db dbname -u username -p password
Reply

#4
Here is an example of exporting collection from node server to local machine:

Host : xxx.xxx.xxx.xx
Port :27017
Username:”XXXX”
Password :”YYYY”
AuthDB : “admin”
“DB”: “mydb”

D:\mongodb-backup>mongodump -h xxx.xxx.xxx.xxx –port 27017 -u “XXXX” -p “YYYY” –authenticationDatabase “admin” –db “mydb”
Reply

#5
<br>

> **This worked for me.**

> Reference: <a href="https://docs.mongodb.com/manual/reference/program/mongodump/">https://docs.mongodb.com/manual/reference/program/mongodump</a>

<br>

**Syntax 1:**

<!-- language: lang-sh -->

mongodump --host <hostname:port> --db <database> --username <username> --password <password> --out <path>

**Syntax 2:**

<!-- language: lang-sh -->

mongodump -h <hostname:port> -d <database> -u <username> -p <password> -o <path>

<br><hr>

**Example 1:**

<!-- language: lang-sh -->

mongodump --host 127.0.0.1:27017 --db db_app --username root --password secret --out /backup/db/app-17-03-07


**Example 2:**

<!-- language: lang-sh -->

mongodump -h 127.0.0.1:27017 -d db_app -u root -p secret -o /backup/db/app-17-03-07
Reply

#6
You can also use gzip for taking backup of one collection and compressing the backup on the fly

mongodump --db somedb --collection somecollection --out - | gzip > collectiondump.gz

Or with a date in the file name:

mongodump --db somedb --collection somecollection --out - | gzip > dump_`date "+%Y-%m-%d"`.gz

Reply

#7
You can use with mongodump with `--uri`

mongodump --uri "mongodb://usersname:[email protected]:27100/dbname?replicaSet=replica_name&authSource=admin" --out "C:\Umesh"

All your collections will store inside the out folder it will create directory name as your Database name and all the collections are bson and metadata will store as json format.

For restore

mongorestore --uri "mongodb://usersname:[email protected]:27100/dbname?replicaSet=replica_name&authSource=admin" -d dbname mongodbumppath

Try this it will work.
Reply

#8
This worked to me like a charm for a single collection with a remote Windows Server.

mongodump --host <remote_ip> --port <mongo_port> --db <remote_db_name> --authenticationDatabase <remote_auth_db> --username <remote_mongo_username> --password <remote_db_pwd> --out <local_DB_backup_folder> --collection <remote_collection_name>
Reply

#9
Use this to get dump using URI:

mongodump --uri=mongodb+srv://john:[email protected]/sales
Reply

#10
On Mac, this is what worked for me (but be sure to use your own real credentials):

```bash
brew tap mongodb/brew
brew install [email protected]
brew services start mongodb/brew/mongodb-community

mongodump --uri "mongodb://usersname:[email protected]:27100/dbname" --out "/Users/some_username/code/mongodb_dumps/dump/"
cd /Users/some_username/code/mongodb_dumps/
mongorestore --nsInclude "*.*"
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through