How to get mongodump --quiet to still report errors?

560 views
Skip to first unread message

Ien Cheng

unread,
May 8, 2016, 7:51:02 PM5/8/16
to mongodb-user
Hi all --

I'd like to run mongodump so that it only outputs errors (to avoid extraneous logwatch reporting for an automated nightly backup script). 

I've tried mongodump --quiet but from a quick test this supressess error messages also (e.g. running it at root folder without permission suppresses the "error creating directory" message that I get without `--quiet`, and). 

How do I get only error output from mongodump?

Thanks, Ien

Kevin Adistambha

unread,
May 12, 2016, 2:08:04 AM5/12/16
to mongodb-user

Hi Ien,

I’d like to run mongodump so that it only outputs errors (to avoid extraneous logwatch reporting for an automated nightly backup script).

Currently, the --quiet option of mongodump and mongoexport suppresses output from database commands, replication activity, and connection events (as described in the mongodump page). The documentation, however, neglected to mention that the --quiet option also suppresses error messages, as you have observed. I have created the DOCS-7853 ticket to document this fact. Thank you for your input in this matter.

Regarding your use case, you may be able to use mongodump exit status to determine if the command was successful. If there is any error during the execution of mongodump, its exit status will be non-zero. In UNIX/Linux system, this exit status can be obtained from the $? variable in bash shell. For example, this command fails due to permission issue and returns an exit status of 1:

$ mongodump -o /dump --quiet
$ echo $?
1

If the command is successful, its exit status will be zero:

$ mongodump -o dump --quiet
$ echo $?
0

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages