4

Basically, I have a problem with using mongodump to back up my MongoDB.

This is the general syntax I use in SSH:

mongodump -d myDatabaseName -o ~/backups/my_backup

This is the resulting message:

Fri Apr 22 20:39:57.304 DATABASE: myDatabaseName   to     /root/backups/my_backup/myDatabaseName

This simply generates a blank folder with no files in it whatsoever. The actual database is fairly large, so not sure what's going on.

I would also like to add that my mongodump client and my MongoDB version are both the same (version 2.4.9).

Not sure how to go about fixing this. Any help is appreciated.

Md Haidar Ali Khan
  • 6,523
  • 9
  • 40
  • 62

4 Answers4

0

I was using the default mongodb-client deb package with Ubuntu. I removed those and installed the mongodb-org-tools package from mongodb.com https://docs.mongodb.com/master/tutorial/install-mongodb-on-ubuntu/?_ga=2.36209632.1945690590.1499275806-1594815486.1499275806

They have other install instructions for your specific OS if you are not on Ubuntu https://www.mongodb.com/download-center?jmp=nav#community

JKOlaf
  • 101
0

As per MongoDB BOL Here Back Up a Database with mongodump Exclude local Database

mongodump excludes the content of the local database in its output.

Required Access

To run mongodump against a MongoDB deployment that has access control enabled, you must have privileges that grant find action for each database to back up. The built-in backup role provides the required privileges to perform backup of any and all databases.

Changed in version 3.2.1: The backup role provides additional privileges to back up the system.profile collections that exist when running with database profiling. Previously, users required an additional read access on this collection.

The mongodump utility backs up data by connecting to a running mongod or mongos instance.

The utility can create a backup for an entire server, database or collection, or can use a query to backup just part of a collection.

When you run mongodump without any arguments, the command connects to the MongoDB instance on the local system (e.g. 127.0.0.1 or localhost) on port 27017 and creates a database backup named dump/ in the current directory.

To backup data from a mongod or mongos instance running on the same machine and on the default port of 27017, use the following command:

mongodump

The data format used by mongodump from version 2.2 or later is incompatible with earlier versions of mongod. Do not use recent versions of mongodump to back up older data stores.

You can also specify the --host and --port of the MongoDB instance that the mongodump should connect to. For example:

mongodump --host mongodb.example.net --port 27017

To specify a different output directory, you can use the --out or -o option:

mongodump --out /data/backup/

To limit the amount of data included in the database dump, you can specify --db and --collection as options to mongodump. For example:

mongodump --collection myCollection --db test

This operation creates a dump of the collection named myCollection from the database test in a dump/ subdirectory of the current working directory.

mongodump overwrites output files if they exist in the backup data folder. Before running the mongodump command multiple times, either ensure that you no longer need the files in the output folder (the default is the dump/ folder) or rename the folders or files.

For further your ref Here & Here

Md Haidar Ali Khan
  • 6,523
  • 9
  • 40
  • 62
0

I faced the same issue (only empty folders were created by mongodump command) with mongodump version 2.4.9, upgrading it helped. You may use following commands to upgrade to version 4.0.4 on ubuntu 14.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-4.0.list
sudo apt-get update -y
sudo apt-get install mongodb-org=4.0.4
Vikas
  • 1
  • 1
0

Make sure mongodb has write permissions for the dump folder.

Old question, I know. But I was struggling with the problem today.

I don't know why it can create folders, and not have the permission to write to them. But for me the answer was to chown the output folder so mongodb was the owner.

sudo chown mongodb ./dump

Then the backup was created successfully.

dval
  • 111
  • 4