日期:2014-05-16  浏览次数:20353 次

MongoDB导出-导入-迁移

linux环境下,将mongodb迁移到同机器,不同端口上。

命令参数:

[mongodb@pera bin]$ ./mongodump --help
Export MongoDB data to BSON files.

options:
  --help                  produce help message
  -v [ --verbose ]        be more verbose (include multiple times for more 
                          verbosity e.g. -vvvvv)
  --version               print the program's version and exit
  -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 toa mongod  server - 
                          needs to lock the datadirectory, so cannot be used 
                          if a mongod is currentlyaccessing the same path
  --directoryperdb        if dbpath specified, each db is in a separate 
                          directory
  --journal               enable journaling
  -d [ --db ] arg         database to use
  -c [ --collection ] arg  collectionto use (some commands)
  -o [ --out ] arg (=dump) output directoryor "-" for stdout
  -q [ --query ] arg      json query
  --oplog                 Use oplog for point-in-time snapshotting
  --repair                try to recover a crashed database
  --forceTableScan        force a table scan (do not use $snapshot)



[mongodb@pera bin]$ ./mongorestore --help
Import BSON files into MongoDB.


usage: ./mongorestore [options] [directory or filenameto restore from]
options:
  --help                 produce help message
  -v [ --verbose ]       be more verbose (include multiple times for more 
                         verbosity e.g. -vvvvv)
  --version              print the program's version and exit
  -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 data