mongodb 的備份恢複匯入與匯出

來源:互聯網
上載者:User

標籤:

匯入匯出use hndb;
db.s.save({name:‘李四‘,age:18,score:80,address:‘鄭州‘});db.s.save({name:‘李三‘,age:8,score:50,address:‘鄭州‘});db.s.save({name:‘張三‘,age:38,score:20,address:‘天津‘});db.s.save({name:‘趙六‘,age:28,score:70,address:‘鄭州‘});db.s.save({name:‘王五五‘,age:19,score:90,address:‘北京‘});

只匯出name欄位舊 mongoexport localhost:27017/admin -d hndb -c s -u admin -p admin -o c:\s.json -f name
新 只匯出name,agemongoexport /h localhost /port 27017 /authenticationDatabase:admin /u admin /p admin /d hndb /c s /o c:\j.js /f name,age
匯出所有屬性mongoexport /h localhost /port 27017 /authenticationDatabase:admin /u admin /p admin /d hndb /c s /o c:\j.js

資料匯入舊mongoimport -d shop -c student -u user -p shop --directoryperdb c:\student.json
mongoimport /h localhost /port 27017 /authenticationDatabase:admin /u admin /p admin /d hndb /c s c:\j.js
刪除資料庫,db.dropDatabase();備份與恢複匯出協助到本地
 
  1. F:\mongodb\bin>mongodump.exe --help >f:/mongodump-help.txt
  2. F:\mongodb\bin>mongorestore.exe --help >f:/mongorestore-help.txt


備份mongodump  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /o c:/
備份指定庫指定表 hndb 集合s 壓縮備份mongodump  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /c s /o c:/ /gzip

備份指定庫指定表 hndb 所有資訊 備份到c:/hndb.zip檔案中mongodump  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
恢複mongorestore  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /dir c:/hndb/
恢複指定的備份,gzip格式mongorestore  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /dir:c:/hndb/ /gzip
恢複 hndb 所有資訊 從檔案c:/hndb.zipmongorestore  /h localhost /port 27017 /u admin /p 123 /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip


資料庫的匯出
 
  1. F:\mongodb\bin>mongodump /h localhost /port 27017 /u admin /p admin /authentica
  2. tionDatabase:admin /d hndb /o c:/


刪除表> db.book.drop();true刪除庫> db.dropDatabase();{ "dropped" : "hndb", "ok" : 1 }刪除庫表,然後備份恢複
 
  1. F:\mongodb\bin>mongorestore /h localhost /port 27017 /u admin /p admin /authent
  2. icationDatabase:admin /d hndb /dir c:/hndb/
壓縮檔的匯出
 
  1. 備份指定庫指定表 hndb 所有資訊 備份到c:/hndb.zip檔案中
  2. mongodump /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
刪除庫表,壓縮檔的匯入
 
  1. 恢複 hndb 所有資訊 從檔案c:/hndb.zip
  2. mongorestore /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /archive:c:/hndb.zip
只匯出stu壓縮檔到hndb裡面
 
  1. F:\mongodb\bin>mongodump /h localhost /port 27017 /u admin /p admin /authentica
  2. tionDatabase:admin /d hndb /c stu /o c:/ /gzip
恢複指定的備份,gzip格式
 
  1. 恢複指定的備份,gzip格式
  2. mongorestore /h localhost /port 27017 /u admin /p admin /authenticationDatabase:admin /d hndb /dir:c:/hndb/ /gzip





來自為知筆記(Wiz)

mongodb 的備份恢複匯入與匯出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.