您好,登錄后才能下訂單哦!
DBA應(yīng)用技巧中如何利用MySQL技能學(xué)習(xí)MongoDB,針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
(1)、mongorestore恢復(fù)工具 我們先看一下此工具的幫助信息:
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 > |
然后下面我們將演示如何恢復(fù)這個庫:
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中的數(shù)據(jù)已經(jīng)被恢復(fù)回來了, 接下來我們到庫里去驗證一下:
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 > |
結(jié)果證明foo庫表已經(jīng)被成功恢復(fù)回來了。
關(guān)于DBA應(yīng)用技巧中如何利用MySQL技能學(xué)習(xí)MongoDB問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。