數(shù)據(jù)庫備份 – mongodump
備份本地所有MongoDB數(shù)據(jù)庫:
復(fù)制代碼 代碼如下:
# mongodump -h 127.0.0.1 --port 27017 -o /root/db/alldb
備份遠(yuǎn)程指定數(shù)據(jù)庫:
復(fù)制代碼 代碼如下:
# mongodump -h 192.168.1.233 --port 27018 -d yourdb -o /root/db/yourdb
更多mongodump詳解
數(shù)據(jù)庫還原-mongorestore
恢復(fù)所有數(shù)據(jù)庫到MongoDB中:
復(fù)制代碼 代碼如下:
# mongorestore -h 127.0.0.1 --port 27018 /root/db/alldb
還原指定數(shù)據(jù)庫:
復(fù)制代碼 代碼如下:
# mongorestore --port 27017 -d yourdb /root/db/yourdb
更多mongorestore詳解
導(dǎo)出集合數(shù)據(jù)-mongoexport
導(dǎo)出數(shù)據(jù)庫中指定集合的數(shù)據(jù):
復(fù)制代碼 代碼如下:
# mongoexport -h 192.168.1.233 --port 27018 -d yourdb -c yourcoll -o /root/yourcoll.json
導(dǎo)出集合中指定字段的數(shù)據(jù),導(dǎo)出的文件格式為csv:
復(fù)制代碼 代碼如下:
# mongoexport -d yourdb -c test -f "id,name,score" --csv -o /root/test.csv
根據(jù)條件導(dǎo)出數(shù)據(jù):
復(fù)制代碼 代碼如下:
# mongoexport -d yourdb -c yourcoll -q '{score:{$gt:80}}' -o /root/yourcoll-bk.json
更多mongoexport詳解
集合數(shù)據(jù)導(dǎo)入-mongoimport
還原導(dǎo)出的集合數(shù)據(jù):
復(fù)制代碼 代碼如下:
# mongoimport -d yourdb -c yourcoll --file /root/yourcoll.json
導(dǎo)入集合數(shù)據(jù),插入或更新現(xiàn)有的數(shù)據(jù):
復(fù)制代碼 代碼如下:
# mongoimport -d test -c yourcoll --file /root/yourcoll.json --upsert
更多mongoimport詳解
MongoDB數(shù)據(jù)庫克隆
命令格式:
復(fù)制代碼 代碼如下:
db.copyDatabase(fromdb, todb, fromhost, username, password)
從遠(yuǎn)程MongoDB中復(fù)制指定數(shù)據(jù)庫到本地:
復(fù)制代碼 代碼如下:
# mongo
> db.copyDatabase("yii2", "lyii2", "192.168.0.69")
更多db.copyDatabase詳解
集合的克隆
命令格式:
復(fù)制代碼 代碼如下:
db.runCommand({ cloneCollection: "namespace>", from: "hostname>", query: { query> } });
從遠(yuǎn)程MongoDB中克隆指定的集合到本地?cái)?shù)據(jù)庫中:
復(fù)制代碼 代碼如下:
# mongo
> db.runCommand({ cloneCollection: "test.user", from: "192.168.0.69", query:{} })
更多cloneCollection詳解
您可能感興趣的文章:- MongoDB單表數(shù)據(jù)的導(dǎo)出和恢復(fù)實(shí)例講解
- MongoDB使用mongoexport和mongoimport命令,批量導(dǎo)出和導(dǎo)入JSON數(shù)據(jù)到同一張表的實(shí)例
- MongoDB 導(dǎo)出導(dǎo)入備份恢復(fù)數(shù)據(jù)詳解及實(shí)例
- mongoDB4.2.8備份恢復(fù)與導(dǎo)出導(dǎo)入(推薦)
- 批量備份還原導(dǎo)入與導(dǎo)出MongoDB數(shù)據(jù)方式