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 database files in the given 
                         path, instead of connecting to amongod  server - 
                         needs to lock the data directory, socannot be used 
                         if a mongod is currently accessingthe 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 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
  --oplogLimit arg       exclude oplog entries newer than provided timestamp 
                         (epoch[:ordinal])
  --keepIndexVersion     don't upgrade indexes to newest version
  --noOptionsRestore     don't restore collection options
  --noIndexRestore       don't restore indexes
  --w arg (=1)           minimum number of replicas per write

主机信息:

[root@pera ~]# more /etc/redhat-release 
Red Hat Enterprise Linux Server release 5.6(Tikanga)
[root@pera ~]# uname -a
Linux pera 2.6.18-238.el5xen #1 SMP Sun Dec 1914:42:02 EST 2010 x86_64 x86_64 x86_64 GNU/Linux
[root@pera ~]# more /proc/cpuinfo |grepmodel 
model           : 15
model name      : Intel(R)Pentium(R) Dual  CPU  E2180  @ 2.00GHz
model           : 15
model name      : Intel(R)Pentium(R) Dual  CPU  E2180  @ 2.00GHz
[root@pera ~]# cat /proc/meminfo |grep Mem
MemTotal:      1784832 kB
MemFree:          5528kB
[root@pera ~]# free
            total       used       free    shared    buffers     cached
Mem:       1784832   1777060       7772          0       964    1600104
-/+ buffers/cache:     175992   1608840
Swap:      5144568    150492    4994076

使用mongodump数据导出

[root@pera bin]# su -mongodb

[mongodb@pera bin]$ ./mongo
MongoDB shell version: 2.2.2
connecting to: test
> show dbs
admin   (empty)
bamuta     19.9443359375GB
local   6.2001953125GB
>

[mongodb@pera bin]$ ./mongodump -d bamuta -o/home/mongodb/backupdmp/

connected to: 127.0.0.1
Mon Sep  9 13:53:53 DATABASE: bamuta       to     /home/mongodb/backupdmp/bamuta
Mon Sep  9 13:53:53     bamuta.system.usersto /home/mongodb/backupdmp/bamuta/system.users.bson
Mon Sep  9 13:53:53             1 objects
Mon Sep  9 13:53:53     Metadatafor bamuta.system.users to /home/mongodb/backupdmp/bamuta/system.users.metadata.json
Mon Sep  9 13:53:53     bamuta.DataInfoto /home/mongodb/backupdmp/bamuta/DataInfo.bson
Mon Sep  9 13:53:56            64300/9301940   0%      (objects)
Mon Sep  9 13:53:59            132100/9301940  1%      (objects)

Mon Sep  9 14:07:19            9257300/9301940 99%     (objects)
Mon Sep  9 14:07:22            9295600/9301940 99%     (objects)
Mon Sep  9 14:07:22             9301940 objects
Mon Sep  9 14:07:22     Metadatafor bamuta.DataInfo to /home/mongodb/backupdmp/bamuta/DataInfo.metadata.json

查看备份的文件:
[mongodb@pera bamuta]$ ls -sh
5.3G DataInfo.bson  4.0KDataInfo.metadata.json  4.0K system.users.bson  4.0Ksystem.users.metadata.json

在另1个端口导入。

先在这个端口创建服务,用户

./mongod --port27019 --dbpath /home/mongodb/mongodbsoft/data27019 --logpath/home/mongodb/mongodbsoft/log27019/

./mongo --port27019 
> use bamuta
> db.addUser ("bamuta","bamuta");

然后导入
[mongodb@pera bin]$  ./mongorestore-d bamuta  --port 27019  /home/mongodb/backupdmp/bamuta

connected to: 127.0.0.1:27019
Tue Sep 10 13:46:21 /home/mongodb/backupdmp/bamuta/DataInfo.bson
Tue Sep 10 13:46:21     going intonamespace [bamuta.DataInfo]
Tue Sep 10 13:46:21 warning: Restoring to bamuta.DataInfowithout dropping. Restored data will be inserted without raising errors; checkyour server log
Tue Sep 10 13:46:24            42747425/5670385368     0%      (bytes)
Tue Sep 10 13:46:27            67203485/5670385368     1%      (bytes)
Tue Sep 10 13:46:30            91269402/5670385368     1%      (bytes)
Tue Sep 10 13:46:33            116882155/5670385368    2%      (bytes)
Tue Sep 10 14:14:18            5659258036/5670385368   99%     (bytes)
9301940 objects found
Tue Sep 10 14:14:20     Creatingindex: { key: { _id: 1 }, ns: "bamuta.DataInfo", name:"_id_" }
Tue Sep 10 15:00:55 warning: Restoring to bamuta.system.userswithout dropping. Restored data will be inserted without raising errors; checkyour server log
1 objects found
Tue Sep 10 15:00:55     Creatingindex: { key: { _id: 1 }, ns: "bamuta.system.users", name:"_id_" }

检查结果

> show dbs
bamuta     13.947265625GB
local   (empty)
test    0.203125GB

可参考的官方文档:

http://docs.mongodb.org/manual/reference/program/mongodump/
http://docs.mongodb.org/manual/reference/program/mongorestore/

MongoDB导出-导入-迁移的更多相关文章

  1. mongodb导出导入实例记录

    mongodb导出导入实例记录 平时很用mongodb,所以用到了,就需要去网上搜索方法,干脆将自己的实际经历记录下来,方便日后使用. # 大致需求 源库:db_name_mongo 源IP:192. ...

  2. MongoDB数据库导出导入迁移

    在server 1导出 /usr/local/mongodb/bin/mongorestore -d adv_new /tmp/mongodb/ 然后会在/tmp/mongodb/目录下生成一个adv ...

  3. mongoDB导出-导入数据

    --导出数据集 C:\MongoDB\db\bin>mongoexport -d ttx-xwms-test -c things -o d:\mongo_data\things.txt C:\M ...

  4. mongodb导出导入数据

    在使用mongodump导出单个表的时候,遇到了一个错误 # mongodump --host xxx --port 27017 --username 'admin' -p '123456' -d 数 ...

  5. MongoDB导出导入功能

    导出脚本: mongo_export.sh !#/bin/bash mongoexport -h x.x.x.x  --port 27017 -d database -c collection  -q ...

  6. SQL SERVER几种数据迁移/导出导入的实践

    SQLServer提供了多种数据导出导入的工具和方法,在此,分享我实践的经验(只涉及数据库与Excel.数据库与文本文件.数据库与数据库之间的导出导入). (一)数据库与Excel 方法1: 使用数据 ...

  7. mongodb 备份 还原 导出 导入

    张映 发表于 2013-12-03 分类目录: nosql 标签:mongodb, 备份, 导入, 导出, 还原 mongodb数据备份和还原主要分为二种,一种是针对于库的mongodump和mong ...

  8. MongoDB的导入导出

    一:MongoDB的导出功能 mongodb提供了导入和导出的功能,分别是MongoDB下载目录下的mongoexport.exe和mongoimport.exe文件 ,具体的导出命令格式如下: mo ...

  9. python 全栈开发,Day126(创业故事,软件部需求,内容采集,显示内容图文列表,MongoDB数据导入导出JSON)

    作业讲解 下载代码: HBuilder APP和flask后端登录 链接:https://pan.baidu.com/s/1eBwd1sVXTNLdHwKRM2-ytg 密码:4pcw 如何打开APP ...

随机推荐

  1. Codeforces Round #316 (Div. 2C) 570C Replacement

    题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...

  2. BZOJ 1617: [Usaco2008 Mar]River Crossing渡河问题( dp )

    dp[ i ] = max( dp[ j ] + sum( M_1 ~ M_( i - j ) ) + M , sum( M_1 ~ M_i ) ) ( 1 <= j < i )  表示运 ...

  3. php随机10-thinkphp 3.1.3 模板继承 布局

    8.25 模板继承 模 板继承是3.1.2版本添加的一项更加灵活的模板布局方式,模板继承不同于模板布局,甚至来说,应该在模板布局的上层.模板继承其实并不难理解,就好比类 的继承一样,模板也可以定义一个 ...

  4. GNU scientific library

    GNU scientific library 是一个强大的C,C++数学库.它涉及的面很广,并且代码效率高,接口丰富.正好最近做的一个项目中用到多元高斯分布,就找到了这个库. GNU scientif ...

  5. cygwin org/apache/zookeeper/KeeperException

    以前用cdh3-0.20的hbase,在windows下面直接启动就行了,但是最近安装0.94以上的,就不行了. 报标题的错误,搜遍网络,几乎都是要加HBASE_CLASSPATH的,后来看老外的文章 ...

  6. Hadoop Hive sql语法详解

    Hadoop Hive sql语法详解 Hive 是基于Hadoop 构建的一套数据仓库分析系统,它提供了丰富的SQL查询方式来分析存储在Hadoop 分布式文件系统中的数据,可以将结构 化的数据文件 ...

  7. BZOJ 1665: [Usaco2006 Open]The Climbing Wall 攀岩

    题目 1665: [Usaco2006 Open]The Climbing Wall 攀岩 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 197  Sol ...

  8. POJ 1472 Coins (多重背包+滚动数组)

    Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 25827 Accepted: 8741 Description Pe ...

  9. 常用的shell命令整理

    工作快一年了,shell命令也玩了一年了.还是有点积累的,下面是本人常用的. 1.pwd | xargs -i basename {}   获取当前所在目录的名称 2.ps -ef|grep -w   ...

  10. IOS中使用像素位图(CGImageRef)对图片进行处理

    IOS中对图片进行重绘处理的方法总结 一.CGImageRef是什么 CGImageRef是定义在QuartzCore框架中的一个结构体指针,用C语言编写.在CGImage.h文件中,我们可以看到下面 ...