Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOOLS-1120 Add option targetDb to mongorestore when use option archive #61

Closed
wants to merge 1 commit into from

Conversation

ArthurHlt
Copy link

When we use the option archive it could be nice to de-archive just one database inside another database which have a different name.

The actual use case is this one:

  1. I have a mongo database created by a SaaS, this service give one database
  2. I dump this database as an archive (Archive is used because of the necessity to dump it as a stream using stdout)
  3. I want to restore my database to a new created database created from SaaS wich have a different database name than the original one
  4. I'm blocked cause it's not possible with --archive option when restoring, it wants to create a database with the name from the original database which is not possible to use

Behavior of the option --targetDb in mongorestore:

  • this can only be used when using --archive option
  • This option make mongorestore to restore just one database at once
  • If you have more than one database in archive and user use --targetDb it will fail, in this case it will ask to set also the option --db
  • else mongorestore will take the only database set in archive and restore it in the database set in --targetDb

For the test, i didn't any test cause I don't see ad to add them, it seems to have no canvas to make this test. It should be in mongorestore_test.go but there is no relevant place for this because --archive option doesn't seem to be tested

ArthurHlt added a commit to orange-cloudfoundry/db-dumper-service that referenced this pull request Mar 29, 2016
Add a new option in mongorestore, see PR: mongodb/mongo-tools#61
Use for now a pre-compiled version of these modified tools
@bompus
Copy link

bompus commented May 9, 2016

+1 to have this fixed. Didn't fully review the PR, but the core problem needs to be solved either way.

@lorepozo
Copy link
Contributor

We've implemented a solution to this, via TOOLS-1234 documented by DOCS-8118. This added namespace inclusion, exclusion, and renaming support. These new CLI options are prefixed with ns because they take a namespace pattern (where asterisks must be escaped for literal use). For example:

# restore everything, but rename prod db to staging
$ mongorestore --nsFrom 'prod.*' --nsTo 'staging.*' --archive='my_archive'
# restore only prod db, and rename it
$ mongorestore --nsInclude 'prod.*' --nsFrom 'prod.*' --nsTo 'staging.*' --archive='my_archive'
# restore everything but the prod db
$ mongorestore --nsExclude 'prod.*' --archive='my_archive'

These changes are committed at 77d72c8.

@lorepozo lorepozo closed this Jul 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants