DBA应用技巧中如何利用MySQL技能学习MongoDB
DBA应用技巧中如何利用MySQL技能学习MongoDB,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
(1)、mongorestore恢复工具 我们先看一下此工具的帮助信息:
[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”库删除了:
[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
>
然后下面我们将演示如何恢复这个库:
[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中的数据已经被恢复回来了, 接下来我们到库里去验证一下:
[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问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。