问题
I have a mongodb production database running on mongo 2.4.8 and I would like to upgrade to 2.6.x.
The way we want to do that is first load the data to another server running 2.6.3 using mongorestore
. However when running the mongorestore
command we get the following error:
Cannot restore users with schema version 1 to a system with server version 2.5.4 or greater
I cannot find anything related to this issue and do't know what to do. In case it matters, the database itself was not created from scratch with mongo 2.4.x but with previous versions.
What ca I do ? Is there another way of doing this other than using mongorestore ?
Thank you in advance for your help ...
回答1:
There are two approaches you can take to upgrade your user schema with the 2.4 mongodump
.
1) Restore into MongoDB 2.4 and then upgrade to 2.6
This follows the normal 2.6 upgrade path. Instead of trying to mongorestore
your 2.4 backup directly into 2.6, restore into a 2.4 instance and then upgrade to 2.6.
It is recommended that before upgrading, you run db.upgradeCheckAllDBs() via a 2.6 mongo
shell. This checks for any potential compatibility issues due to changes in MongoDB 2.6. For example, 2.6 implements stronger enforcement of index field definitions and key length restrictions.
2) Restore into MongoDB 2.6 using 2.4 mongorestore
and then upgrade the user schema
This approach requires the MongoDB 2.4 version of mongorestore
start up your MongoDB 2.6
mongod
without auth enabledmongorestore
your backup using a 2.4 version ofmongorestore
run the authSchemaUpgrade command in your 2.6
mongo
shell:db.adminCommand({authSchemaUpgrade: 1 });
restart your 2.6
mongod
with auth enabled
回答2:
Three approaches that I can think of:
First, if you are running as a replica set, I'd upgrade the members one by one. If you're not running as a replica set that's bad, MongoDB is really not designed for production usage with a single instance. Details on converting to a replica set and in a rolling upgrade here: http://docs.mongodb.org/manual/release-notes/2.6-upgrade/ and here: http://docs.mongodb.org/v2.6/tutorial/convert-standalone-to-replica-set/#
Second, if you are running on a file system that supports snapshots (like Amazon EBS or Linux LVM) you can snapshot the database files, restore to a new file system and start up a new mongod process using 2.6. http://docs.mongodb.org/manual/tutorial/backup-with-filesystem-snapshots/
Third, try exporting the data via mongoexport and loading it via mongoimport. It's not the same as mongodump/mongorestore so it has some limitations (it's not a full backup of the database, just a text dump of the collections) but might help you get past this issue with mongorestore: http://docs.mongodb.org/v2.6/core/import-export/
来源:https://stackoverflow.com/questions/25181769/mongorestore-issue-cannot-restore-users-with-schema-version-1-to-a-system-with