patternMajor
How restore from .gz backup with new database name using mongorestore r3.2.9?
Viewed 0 times
newmongorestorewithdatabasenameusinghowfromrestorebackup
Problem
I'm trying to backup/restore mongodb database to/from .gz files as sample script here
Step 01 i.e. back up is good for both mongodb version
How can I get mongorestore version
p.s.
We have the solution here but that requires the backup to be a folder; my backup files are huge i.e. 1Gb-2Gb so the extraction is too much time-consuming.
#01 create .gz backup - ok for r3.2.9 and r3.4.10
mongodump --db ${DB_NAME} --gzip --archive=${BACKUP_FILE_GZ}
#02 restore from .gz file - NOT ok for r3.2.9
mongorestore --gzip --archive=${BACKUP_FILE_GZ} --nsFrom "${DB_NAME}.*" --nsTo "${DB_NAME_RESTORE}.*"Step 01 i.e. back up is good for both mongodb version
r3.2.9 and r3.4.10; though step 02 NOT works for r3.2.9How can I get mongorestore version
r3.2.9 to restore from .gz file and be able to rename the database?p.s.
We have the solution here but that requires the backup to be a folder; my backup files are huge i.e. 1Gb-2Gb so the extraction is too much time-consuming.
Solution
With 3.2.x you cannot use
Now you get a directory with gzipped files and you can restore all (or just one) collections to a different database.
--nsFrom or --nsTo parameters. This pair of commands should work in all versions:mongodump --db ${DB_NAME} --gzip -o ${BACKUP_FILE_GZ}
mongorestore --gzip --db "${DB_NAME_RESTORE}" ${BACKUP_FILE_GZ}/${DB_NAME}Now you get a directory with gzipped files and you can restore all (or just one) collections to a different database.
Code Snippets
mongodump --db ${DB_NAME} --gzip -o ${BACKUP_FILE_GZ}
mongorestore --gzip --db "${DB_NAME_RESTORE}" ${BACKUP_FILE_GZ}/${DB_NAME}Context
StackExchange Database Administrators Q#189928, answer score: 20
Revisions (0)
No revisions yet.