mongodb的备份还原案例(二)

2014-11-24 14:33:53 · 作者: · 浏览: 3
metadata.json -rw-r--r-- 1 root root 128 Jul 3 00:41 system.indexes.bson -rw-r--r-- 1 root root 205 Jul 3 00:41 user.bson -rw-r--r-- 1 root root 91 Jul 3 00:41 user.metadata.json [root@Mongodb test]#

备份 出来的有带有数据的bson文件,还有index的bson文件
mongorestore是Mongodb从备份中恢复数据的工具,它主要用来获取mongodump的输出结果,并将备份的数据插入到运行的Mongodb中。
mongorestore用法;
[root@Mongodb ~]# mongorestore --help
Import BSON files into MongoDB.


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)
  --version                             print the program's version and exit
  -h [ --host ] arg                     mongo host to connect to ( /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
  --authenticationDatabase arg          user source (defaults to dbname)
  --authenticationMechanism arg (=MONGODB-CR)
                                        authentication mechanism
  --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                      each db is in a separate directly 
                                        (relevant only if dbpath specified)
  --journal                             enable journaling (relevant only if 
                                        dbpath specified)
  -d [ --db ] arg                       database to use
  -c [ --collection ] arg               collection to use (some commands)
  --objcheck                            validate
object before inserting (default) --noobjcheck don't 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 include oplog entries before the provided Timestamp (seconds[:ordinal]) during the oplog replay; the ordinal value is optional --keepIndexVersion don't upgrade indexes to newest version --noOptionsRestore don't restore collection options --noIndexRestore don't restore indexes --w arg (=0) minimum number of replicas per write You have new mail in /var/spool/mail/root [root@Mongodb ~]# 以下进行恢复过程记录; [root@Mongodb-B mongo]# scp -P 22 -r root@192.168.155.198:/data/db/dump /usr/local/ ------拷贝备份的目录文件到另一台新mongodb服务器上进行恢复 root@192.168.155.198's password: code.bson 100% 1036 1.0KB/s 00:00 system.indexes.bson 100% 128 0.1KB/s 00:00 user.bson 100% 205 0.2KB/s 00:00 code.metadata.json 100% 91 0.1KB/s 00:00 user.metadata.json 100% 91 0.1KB/s 00:00 [root@Mongodb-B mongo]# cd /usr/local/ [root@Mongodb-B local]# ls bin etc include libexec mongodb-linux-i686-2.4.4.tgz share dump games lib mongo sbin src [root@Mongodb-B local]# cd dump/ [root@Mongodb-B dump]# ls test [root@Mongodb-B dump]# ll ------------看到拷贝过来的备份目录内容 total 8 drwxr-xr-x 2 root root 4096 Jul 3 01:07 test [root@Mongodb-B dump]# cd test/ [root@Mongodb-B test]# ls code.bson system.indexes.bson user.metadata.json code.metadata.json user.bson [root@Mongodb-B test]# ll -----------看到拷贝过来的备份目录内容 total 40 -rw-r--r-- 1 root root 1036 Jul 3 01:07 code.bson -rw-r--r-- 1 root root 91 Jul 3 01:07 code.metadata.json -rw-r--r-- 1 root root 128 Jul 3 01:07 system.indexes.bson -rw-r--r-- 1 root root 205 Jul 3 01:07 user.bson -rw-r--r-- 1 root root 91 Jul 3 01:07 user.metadata.json