在Debian系统上备份和恢复MongoDB数据库,可以使用mongodump
和mongorestore
命令。以下是详细的步骤和示例:
mongodump --host localhost --port 27017 --out /backup/mongodb/
mongodump --host localhost --port 27017 -d mydb --out /backup/mongodb/
mongodump --host localhost --port 27017 -d mydb -c mycollection --out /backup/mongodb/
mongodump --host localhost --port 27017 -d mydb -c mycollection -q '{ age: { $gt: 30 } }' --out /backup/mongodb/
mongodump --host localhost --port 27017 -d mydb -c mycollection --out /backup/mongodb/ --gzip
mongorestore --host localhost --port 27017 /backup/mongodb/
mongorestore --host localhost --port 27017 -d mydb /backup/mongodb/mydb/*
mongorestore --host localhost --port 27017 -d mydb -c mycollection /backup/mongodb/mydb/mycollection/*
在执行备份和恢复操作时,请确保你有足够的权限,并且MongoDB服务正在运行或已停止,具体取决于你的备份策略。