您好,登錄后才能下訂單哦!
DBA應用技巧中如何利用MySQL技能學習MongoDB,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
(1)、mongorestore恢復工具 我們先看一下此工具的幫助信息:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | [root@localhost bin]# ./mongorestore --help usage: ./mongorestore [options] [directory or filename to restore from ] options:
--help produce help message
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
-h [ --host ] arg mongo host to connect to ( <set name>/s1,s2 for sets)
--port arg server port. Can also use --host hostname:port
--ipv6 enable IPv6 support (disabled by default)
-u [ --username ] arg username
-p [ --password ] arg password
--dbpath arg directly access mongod database files in the given
path, instead of connecting to a mongod server -
needs to lock the data directory, so cannot be used
if a mongod is currently accessing the same path
--directoryperdb if dbpath specified, each db is in a separate
directory
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
--objcheck validate object before inserting
--filter arg filter to apply before inserting
--drop drop each collection before import
--oplogReplay replay oplog for point-in-time restore [root@localhost bin]# |
例如我們先將”foo”庫刪除了:
1 2 3 4 5 6 7 8 9 10 11 12 | [root@localhost bin]# ./mongo MongoDB shell version: 1.8.1 connecting to : test > use foo switched to db foo > db.dropDatabase(); { "dropped" : "foo" , "ok" : 1 } > show dbs admin 0.0625GB local (empty) test 0.0625GB > |
然后下面我們將演示如何恢復這個庫:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [root@localhost bin]# ./mongorestore --directoryperdb /data/dump connected to : 127.0.0.1 Sun Apr 22 12:01:27 /data/dump/foo/t1.bson Sun Apr 22 12:01:27 going into namespace [foo.t1] Sun Apr 22 12:01:27 2 objects found Sun Apr 22 12:01:27 /data/dump/foo/t2.bson Sun Apr 22 12:01:27 going into namespace [foo.t2] Sun Apr 22 12:01:27 1 objects found Sun Apr 22 12:01:27 /data/dump/foo/system.users.bson Sun Apr 22 12:01:27 going into namespace [foo.system.users] Sun Apr 22 12:01:27 1 objects found Sun Apr 22 12:01:27 /data/dump/foo/system.indexes.bson Sun Apr 22 12:01:27 going into namespace [foo.system.indexes] Sun Apr 22 12:01:27 { name : "_id_" , ns: "foo.system.users" , key : { _id: 1 }, v: 0 } Sun Apr 22 12:01:27 { name : "_id_" , ns: "foo.t2" , key : { _id: 1 }, v: 0 } Sun Apr 22 12:01:27 { name : "_id_" , ns: "foo.t1" , key : { _id: 1 }, v: 0 } Sun Apr 22 12:01:27 3 objects found [root@localhost bin]# |
通過工具返回信息,我們可以看到foo中的數據已經被恢復回來了, 接下來我們到庫里去驗證一下:
1 2 3 4 5 6 7 8 9 10 11 | [root@localhost bin]# ./mongo MongoDB shell version: 1.8.1 connecting to : test > use foo switched to db foo > show collections; system.indexes system.users t1 t2 > |
結果證明foo庫表已經被成功恢復回來了。
關于DBA應用技巧中如何利用MySQL技能學習MongoDB問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。