Skip to content

Commit

Permalink
auth source added in mongodb. authentication issue fixed with mongodb… (
Browse files Browse the repository at this point in the history
#379)

* auth source added in mongodb. authentication issue fixed with mongodb connections

* unused utils import removed in db/postgresql.py

* Documentation added for auth enabled mongoDB Connection

Co-authored-by: Ajay Saini <[email protected]>
  • Loading branch information
Ajaysainisd and ajayarthonsys authored Dec 25, 2020
1 parent e603f16 commit 9d1909c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dbbackup/db/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def _create_dump(self):
cmd += ' --username {}'.format(self.settings['USER'])
if self.settings.get('PASSWORD'):
cmd += ' --password {}'.format(utils.get_escaped_command_arg(self.settings['PASSWORD']))
if self.settings.get('AUTH_SOURCE'):
cmd += ' --authenticationDatabase {}'.format(self.settings['AUTH_SOURCE'])
for collection in self.exclude:
cmd += ' --excludeCollection {}'.format(collection)
cmd += ' --archive'
Expand All @@ -37,6 +39,8 @@ def _restore_dump(self, dump):
cmd += ' --username {}'.format(self.settings['USER'])
if self.settings.get('PASSWORD'):
cmd += ' --password {}'.format(utils.get_escaped_command_arg(self.settings['PASSWORD']))
if self.settings.get('AUTH_SOURCE'):
cmd += ' --authenticationDatabase {}'.format(self.settings['AUTH_SOURCE'])
if self.object_check:
cmd += ' --objcheck'
if self.drop:
Expand Down
1 change: 0 additions & 1 deletion dbbackup/db/postgresql.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from urllib.parse import quote
import logging

from dbbackup import utils
from .base import BaseCommandDBConnector
from .exceptions import DumpError

Expand Down
19 changes: 19 additions & 0 deletions docs/databases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,25 @@ MongoDB
MongoDB uses by default :class:`dbbackup.db.mongodb.MongoDumpConnector`. it
uses ``mongodump`` and ``mongorestore`` for its job.

For AuthEnabled MongoDB Connection, you need to add one custom option ``AUTH_SOURCE`` in your ``DBBACKUP_CONNECTORS``. ::

DBBACKUP_CONNECTORS = {
'default': {
...
'AUTH_SOURCE': 'admin',
}
}

Or in ``DATABASES`` one: ::

DATABASES = {
'default': {
...
'AUTH_SOURCE': 'admin',
}
}


OBJECT_CHECK
~~~~~~~~~~~~

Expand Down

0 comments on commit 9d1909c

Please sign in to comment.