在 Debian 上进行 MongoDB 数据迁移的实用步骤
一 场景与方法选择
二 准备与环境检查
sudo apt update && sudo apt install -y mongodb-clientsmongodump --version 验证。三 全量迁移步骤 BSON mongodump/mongorestore
mongodump --host <src_host> --port <src_port> --username <user> --password <pass> --authenticationDatabase admin --out /backup/mongodb/$(date +%Y%m%d%H%M%S)mongodump --host <src_host> --port <src_port> --username <user> --password <pass> --authenticationDatabase admin --db <db> --out /backup/mongodb/<ts>scp -r /backup/mongodb/<ts> user@debian-host:/backup/mongodb/mongorestore --host <debian_host> --port <debian_port> --username <user> --password <pass> /backup/mongodb/<ts>mongorestore --host <debian_host> --port <debian_port> --username <user> --password <pass> --db <db> /backup/mongodb/<ts>/<db>mongo --db <db> --quiet --eval 'db.getCollectionNames()'mongo --db <db> --eval 'db.<coll>.countDocuments({})'四 其他常见场景与命令
mongodump --host <src_host> --port <src_port> --db <db> --collection <coll> --out /backup/mongodb/<ts>mongorestore --host <debian_host> --port <debian_port> --db <db> /backup/mongodb/<ts>/<db>/<coll>.bsonmongorestore --host <debian_host> --port <debian_port> --db <target_db> --collection <target_coll> /backup/mongodb/<ts>/<db>/<coll>.bsonmongoexport --uri="mongodb://<src_host>:<src_port>/<db>" --collection=<coll> --out=<coll>.jsonmongoimport --uri="mongodb://<debian_host>:<debian_port>/<db>" --collection=<coll> --file=<coll>.jsonmongodump --uri="mongodb://<src_host>:<src_port>/<db>" --archive=<db>.archivemongorestore --uri="mongodb://<debian_host>:<debian_port>/<db>" --archive=<db>.archive五 验证与注意事项