以下是在CentOS上进行MongoDB数据迁移的常用方法:
mongodump --host <源IP> --port <源端口> --username <用户名> --password <密码> --authenticationDatabase admin --db <数据库名> --out /备份路径
mongodump --host 192.168.1.100 --port 27017 -u admin -p 123456 --db test --out /data/backup
scp -r /备份路径 <目标IP>:/目标路径
mongorestore --host <目标IP> --port <目标端口> --username <用户名> --password <密码> --authenticationDatabase admin /目标路径/<数据库名>
mongodump --host <源IP> --port <源端口> --username <用户名> --password <密码> --authenticationDatabase admin --query '{<条件>}' --oplog --out /增量备份路径
mongorestore --host <目标IP> --port <目标端口> --username <用户名> --password <密码> --authenticationDatabase admin --oplogReplay /增量备份路径
sudo systemctl stop mongod
rsync -av /var/lib/mongo/ <目标IP>:/var/lib/mongo/
(需确保目标服务器已安装MongoDB且配置一致)sudo systemctl start mongod
sudo
)。scp -C
)。mongo
客户端执行db.getCollectionNames()
或查询关键数据验证完整性。参考来源: