MongoDB整理筆記のDump & Restore

來源:互聯網
上載者:User

標籤:

   備份

[[email protected] bin]# ./mongodump -d my_mongodb connected to: 127.0.0.1  DATABASE: my_mongodb     to     dump/my_mongodb          my_mongodb.system.indexes to dump/my_mongodb/system.indexes.bson                  1 objects          my_mongodb.user to dump/my_mongodb/user.bson                  2 objects [[email protected] bin]# ll 總計 67648  -rwxr-xr-x 1 root root 7508756 2011-04-06 bsondump drwxr-xr-x 3 root root    4096 04-10 23:54 dump -rwxr-xr-x 1 root root 2978016 2011-04-06 mongo 
View Code

   此時,會在目前的目錄下建立一個dump目錄,用於存放備份出來的檔案,當然也可以指定備份存放的目錄。

[email protected] bin]# ./mongodump -d my_mongodb -o my_mongodb_dump connected to: 127.0.0.1  DATABASE: my_mongodb     to     my_mongodb_dump/my_mongodb         my_mongodb.system.indexes  to  my_mongodb_dump/my_mongodb/system.indexes.bson                  1 objects          my_mongodb.user to my_mongodb_dump/my_mongodb/user.bson           2 objects [[email protected] bin]# 
View Code

   這個例子中將備份檔案存在了目前的目錄下的my_mongodb_dump目錄下

   恢複

   由於剛剛已經做了備份,所以我們先講庫my_mongodb刪除掉  

> use my_mongodb  switched to db my_mongodb > db.dropDatabase() { "dropped" : "my_mongodb", "ok" : 1 } > show dbs  admin   (empty) local   (empty) test    (empty) >   
View Code

   接下來,我們進行資料恢複

[[email protected] bin]# ./mongorestore -d my_mongodb my_mongodb_dump/connected to: 127.0.0.1  Wed Apr 11 00:03:03 my_mongodb_dump/my_mongodb/user.bson Wed Apr 11 00:03:03      going into namespace [my_mongodb.user] Wed Apr 11 00:03:03      2 objects found  Wed Apr 11 00:03:03 my_mongodb_dump/my_mongodb/system.indexes.bson Wed Apr 11 00:03:03      going into namespace [my_mongodb.system.indexes] Wed Apr 11 00:03:03 { name: "_id_", ns: "my_mongodb.user", key: { _id: 1 }, v: 0 } Wed Apr 11 00:03:03      1 objects found [[email protected] bin]#
View Code

   經驗證資料庫又回來了,其實要想恢複資料庫,大可不必先刪除my_mongodb庫,只要說明-drop參數,就可以在恢複的時候先刪除表然後再向表中插入資料。

MongoDB整理筆記のDump & Restore

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.