[root@master ~]# cd /opt/mongodb
[root@master mongodb]# ls
bin data GNU-AGPL-3.0 log README THIRD-PARTY-NOTICES
[root@master mongodb]# cd bin/
[root@master bin]# l
-bash: l: command not found
[root@master bin]# ls
bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongostat
[root@master bin]# ./mongod help
Invalid command: help
Allowed options:
General options:
-h [ --help ] show this usage information
--version show version information
-f [ --config ] arg configuration file specifying additional options
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
--quiet quieter output
--port arg specify port number
--bind_ip arg comma separated list of ip addresses to listen on - all
local ips by default
--logpath arg file to send all output to instead of stdout
--logappend append to logpath instead of over-writing
--pidfilepath arg full path to pidfile (if not set, no pidfile is
created)
--fork fork server process
--dbpath arg directory for datafiles
--directoryperdb each database will be stored in a separate directory
--repairpath arg root directory for repair files - defaults to dbpath
--cpu periodically show cpu and iowait utilization
--noauth run without security
--auth run with security
--objcheck inspect client data for validity on receipt
--quota enable db quota management
--quotaFiles arg number of files allower per db, requires --quota
--appsrvpath arg root directory for the babble app server
--nocursors diagnostic/debugging option
--nohints ignore query hints
--nohttpinterface disable http interface
--rest turn on simple rest api
--noscripting disable scripting engine
--noprealloc disable data file preallocation
--smallfiles use a smaller default file size
--nssize arg (=16) .ns file size (in MB) for new databases
--diaglog arg 0=off 1=W 2=R 3=both 7=W+some reads
--sysinfo print some diagnostic system information
--upgrade upgrade db if needed
--repair run repair on all dbs
--notablescan do not allow table scans
--syncdelay arg (=60) seconds between disk syncs (0=never, but not
recommended)
--profile arg 0=off 1=slow, 2=all
--slowms arg (=100) value of slow for profile and console log
--maxConns arg max number of simultaneous connections
--nounixsocket disable listening on unix sockets
--ipv6 enable IPv6 support (disabled by default)
Replication options:
--master master mode
--slave slave mode
--source arg when slave: specify master as <server:port>
--only arg when slave: specify a single database to replicate
--pairwith arg address of server to pair with
--arbiter arg address of arbiter server
--slavedelay arg specify delay (in seconds) to be used when applying
master ops to slave
--fastsync indicate that this instance is starting from a dbpath
snapshot of the repl peer
--autoresync automatically resync if slave data is stale
--oplogSize arg size limit (in MB) for op log
--opIdMem arg size limit (in bytes) for in memory storage of op ids
Sharding options:
--configsvr declare this is a config db of a cluster
--shardsvr declare this is a shard db of a cluster
--noMoveParanoia turn off paranoid saving of data for moveChunk. this
is on by default for now, but default will switch
[root@master bin]# cd ../
[root@master mongodb]# vu start_mongo
-bash: vu: command not found
[root@master mongodb]# vi start_mongo
#!/bin/bash
bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend --port=6699 --fork
~
~
[root@master mongodb]# netstat -tnpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:868 0.0.0.0:* LISTEN 2806/rpc.statd
tcp 0 0 0.0.0.0:6699 0.0.0.0:* LISTEN 3519/mongod
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2765/portmap
tcp 0 0 0.0.0.0:7699 0.0.0.0:* LISTEN 3519/mongod
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3080/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3138/sendmail: acce
tcp 0 0 :::22 :::* LISTEN 3051/sshd
[root@master mongodb]# cd bin/
[root@master bin]# ls
bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongosniff mongostat
[root@master bin]# mongo --help
-bash: mongo: command not found
[root@master bin]# ./mongo --help
MongoDB shell version: 1.6.3
usage: ./mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.169.0.5/foo foo database on 192.168.0.5 machine
192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
options:
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no 'db address'
arg expected
--quiet be less chatty
--port arg port to connect to
--host arg server to connect to
--eval arg evaluate javascript
-u [ --username ] arg username for authentication
-p [ --password ] arg password for authentication
-h [ --help ] show this usage information
--version show version information
--ipv6 enable IPv6 support (disabled by default)
file names: a list of files to run. files have to end in .js and will exit after unless --shell is specified
[root@master bin]# ./bsondump --help
usage: ./bsondump [options] <bson filename>
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 ("left,right" for pairs)
--port arg server port. Can also use --host hostname:port
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-u [ --username ] arg username
-p [ --password ] arg password
--ipv6 enable IPv6 support (disabled by default)
--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
--objcheck validate object before inserting
--filter arg filter to apply before inserting
--type arg (=json) type of output: json,debug
[root@master bin]# ./mongodump --help
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 ("left,right" for pairs)
--port arg server port. Can also use --host hostname:port
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-u [ --username ] arg username
-p [ --password ] arg password
--ipv6 enable IPv6 support (disabled by default)
--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
-o [ --out ] arg (=dump) output directory
-q [ --query ] arg json query
[root@master 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 ("left,right" for pairs)
--port arg server port. Can also use --host hostname:port
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-u [ --username ] arg username
-p [ --password ] arg password
--ipv6 enable IPv6 support (disabled by default)
--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
--objcheck validate object before inserting
--filter arg filter to apply before inserting
--drop drop each collection before import
--indexesLast wait to add indexes (faster if data isn't inserted in
index order)
[root@master bin]# ./mongostat --help
usage: ./mongostat [options] [sleep time]
sleep time: time to wait (in seconds) between calls
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 ("left,right" for pairs)
--port arg server port. Can also use --host hostname:port
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-u [ --username ] arg username
-p [ --password ] arg password
--ipv6 enable IPv6 support (disabled by default)
--noheaders don't output column names
-n [ --rowcount ] arg (=0) number of stats lines to print (0 for indefinite)
--http use http instead of raw db connection
Fields
inserts/s - # of inserts per second
query/s - # of queries per second
update/s - # of updates per second
delete/s - # of deletes per second
getmore/s - # of get mores (cursor batch) per second
command/s - # of commands per second
flushes/s - # of fsync flushes per second
mapped - amount of data mmaped (total data size) megabytes
visze - virtual size of process in megabytes
res - resident size of process in megabytes
faults/s - # of pages faults/sec (linux only)
locked - percent of time in global write lock
idx miss - percent of btree page misses (sampled)
q t|r|w - ops waiting for lock from db.currentOp() (total|read|write)
conn - number of open connections
[root@master bin]# ./mongos --help
Sharding options:
-h [ --help ] show this usage information
--version show version information
-f [ --config ] arg configuration file specifying additional options
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
--quiet quieter output
--port arg specify port number
--bind_ip arg comma separated list of ip addresses to listen on - all
local ips by default
--logpath arg file to send all output to instead of stdout
--logappend append to logpath instead of over-writing
--pidfilepath arg full path to pidfile (if not set, no pidfile is
created)
--fork fork server process
--configdb arg 1 or 3 comma separated config servers
--test just run unit tests
--upgrade upgrade meta data version
--chunkSize arg maximum amount of data per chunk
--ipv6 enable IPv6 support (disabled by default)
[root@master bin]# ./mongo --port 6699
MongoDB shell version: 1.6.3
connecting to: 127.0.0.1:6699/test
> show dbs;
admin
local
test_mongo
> use test_mongo;
switched to db test_mongo
> show collections;
system.indexes
test
> db.test.find();
{ "_id" : ObjectId("595e3ca9e2baea15d0c694b9"), "id" : 2, "name" : "绋娣2" }
{ "_id" : ObjectId("595e3cb4e2baea15d0c694ba"), "id" : 1, "name" : "绋娣1" }
{ "_id" : ObjectId("595e3cc0e2baea15d0c694bb"), "id" : 3, "name" : "绋娣3" }
>
MongoDB 备份(mongodump)与恢复(mongorestore)
MongoDB数据备份
在Mongodb中我们使用mongodump命令来备份MongoDB数据。该命令可以导出所有数据到指定目录中。
mongodump命令可以通过参数指定导出的数据量级转存的服务器。
语法
mongodump命令脚本语法如下:
>mongodump -h dbhost -d dbname -o dbdirectory
-h:MongDB所在服务器地址,例如:127.0.0.1,当然也可以指定端口号:127.0.0.1:27017
-d:需要备份的数据库实例,例如:test
-o:备份的数据存放位置,例如:c:\data\dump,当然该目录需要提前建立,在备份完成后,系统自动在dump目录下建立一个test目录,这个目录里面存放该数据库实例的备份数据。
MongoDB数据恢复
mongodb使用 mongorestore 命令来恢复备份的数据。
语法
mongorestore命令脚本语法如下:
>mongorestore -h <hostname><:port> -d dbname <path>
--host <:port>, -h <:port>:
MongoDB所在服务器地址,默认为: localhost:27017
--db , -d : 需要恢复的数据库实例,例如:test,当然这个名称也可以和备份时候的不一样,比如test2
--drop: 恢复的时候,先删除当前数据,然后恢复备份的数据。就是说,恢复后,备份后添加修改的数据都会被删除,慎用哦!
<path>: mongorestore 最后的一个参数,设置备份数据所在位置,例如:c:\data\dump\test。
你不能同时指定 <path> 和 --dir 选项,--dir也可以设置备份目录。
--dir: 指定备份的目录
你不能同时指定 <path> 和 --dir 选项。
[root@master bin]#
[root@master bin]# ./mongodump -d test_mongo -o /tmp/
couldn't connect to [127.0.0.1] couldn't connect to server 127.0.0.1
[root@master bin]# ./mongodump -d test_mongo -o /tmp/ --port 6699
connected to: 127.0.0.1:6699
DATABASE: test_mongo to /tmp/test_mongo
test_mongo.system.indexes to /tmp/test_mongo/system.indexes.bson
1 objects
test_mongo.test to /tmp/test_mongo/test.bson
3 objects
[root@master bin]# ./mongorestore --port 6699 -d local --directoryperdb /tmp/test_mongo/
connected to: 127.0.0.1:6699
Thu Jul 6 15:21:11 /tmp/test_mongo/system.indexes.bson
Thu Jul 6 15:21:11 going into namespace [local.system.indexes]
Thu Jul 6 15:21:11 1 objects found
Thu Jul 6 15:21:11 /tmp/test_mongo/test.bson
Thu Jul 6 15:21:11 going into namespace [local.test]
Thu Jul 6 15:21:11 3 objects found
[root@master bin]#
相关推荐
通过上述策略和技术手段,网易游戏成功实现了对PB级MongoDB数据的高效备份与快速恢复,有效保障了业务连续性和数据安全性。这些实践经验对于其他大型互联网企业和游戏开发者来说具有重要的参考价值。
网易游戏MongoDB数据备份与恢复实践 本文将详细介绍网易游戏MongoDB数据备份与恢复实践,涵盖了MongoDB在网易游戏端游数据中心的应用、扩展性、业务需求、priority=0资源情况等多方面的内容,并对MongoDB在网易游戏...
MongoDB 数据备份 在 MongoDB 中我们使用 mongodump 命令来备份 MongoDB 数据 语法如下: > mongodump -h dbhost -d dbname -o dbdirectory -u user -p password -h MongDB所在服务器地址,例如:127.0.0.1,当然...
**MongoDB数据同步与增量备份.pptx 和 MongoDB数据同步.pptx** 可能是关于如何执行MongoDB数据同步和增量备份的演示文稿,可能包含了具体的案例和操作流程,对于理解相关概念和操作流程非常有价值。 **tokusync** ...
MongoDB 是一个高性能、开源的文档型数据库,广泛应用于各种规模的企业和项目中。...通过上述方法,你可以有效地管理和保护MongoDB的分片和复制集数据,确保在系统出现问题时能够快速恢复,从而保障业务的连续性。
MongoDB 秒级备份恢复方案 ...本资源总结了 MongoDB 秒级备份恢复方案的技术创新和解决方案,包括备份恢复方案的重要性、备份策略、逻辑备份 vs 物理备份、增量备份原理、问题与挑战和解决方案等内容。
备份恢复的有效性验证、备份存储以及恢复策略是阿里云MongoDB备份恢复功能的重要组成部分。用户可以根据实际需求,选择自动或手动备份,设置备份周期和保留时间。为了防止数据丢失,备份可以存储在高可靠的OSS(对象...
MongoDB提供了`mongodump`和`mongorestore`命令行工具来进行数据备份与恢复。`mongodump`用于生成数据库的二进制备份,而`mongorestore`则用于从这些备份中恢复数据。 1. **基础全量备份**:执行全量备份是创建增量...
本文将详细介绍MongoDB在多数据中心环境中的部署与管理。 首先,我们来了解MongoDB多数据中心部署的重要意义。业务关键型应用始终需要连续的可用性,这是由其服务的连续性和地理分布的必要性决定的。MongoDB通过...
本文将深入探讨 MongoDB 的无参数备份与恢复以及带参数备份与恢复的实例。 1. 无参数备份与恢复 无参数备份是指不指定特定选项的备份操作。在 MongoDB 中,可以使用 `mongodump` 命令进行无参数备份。当在本地启动...
在运维MongoDB的过程中,数据的备份与恢复是至关重要的环节,以确保数据的安全性和业务连续性。本篇文章将详细讲解MongoDB的常用备份工具`mongoexport`、`mongoimport`以及`mongodump`和`mongorestore`的使用方法。 ...
头歌6.7MongoDB 实验-数据备份和恢复
然而,随着数据量的增长和业务需求的变化,如何有效地进行数据备份与恢复成为了一个至关重要的问题。本文将深入探讨MongoDB的两种主要备份方式——冷备份与热备份,并详细介绍其操作流程。 #### 二、冷备份与恢复 *...
mongodb备份与恢复 mongodb备份是非常有必要的,数据的重要性不言而喻。mongodb备份方式有三种...mongodb备份与恢复非常重要,需要根据具体情况选择合适的备份方式,并遵循相应的恢复步骤,以确保数据的安全和可靠性。
MongoDB提供了`mongodump`工具来执行数据备份。`mongodump`可以备份整个服务器、单一数据库或单一集合。默认情况下,它会备份本地主机(127.0.0.1或localhost)的27017端口上的数据,并将备份文件保存在名为`dump`的...
`mongodump`将数据库的数据和元数据转换为BSON格式的文件,便于存储和恢复。在`mongodump_oplog.py`脚本中,这一步可能包括连接到MongoDB服务器,指定需要备份的数据库和集合,然后调用`mongodump`命令执行备份。 ...
### MongoDB数据备份 MongoDB提供了`mongodump`命令来创建数据库的备份。备份的基本语法如下: ```bash mongodump -h <hostname> -u <username> -p <password> -d <database_name> -c <collection_name> -o ``` ...
- **MongoDB数据恢复**: - 恢复全部数据库: ```bash mongorestore --drop --directoryPerDb /home/backup/mongod_bak/mongod_bak_now/2018_02_28_050502/ ``` - 恢复单个数据库: ```bash mongorestore --...