一,通过copy mogodb文件的方式备份还原。(建议copy的时候mogodb锁定禁止写入,避免导出的文件与原库文件部分数据不一致,或者导出的文件格式损坏)
1,通过FTP将生产的mogodb文件copy下来
2,在window下恢复
C:\Program Files\MongoDB 2.6 Standard\bin>mongod.exe -dbpath E:\mogo_data 2015-05-27T12:44:16.313+0800 Hotfix KB2731284 or later update is not installed, will zero-out data files 2015-05-27T12:44:16.316+0800 [initandlisten] MongoDB starting : pid=6256 port=27 017 dbpath=E:\mogo_data 64-bit host=PC201505061049 2015-05-27T12:44:16.317+0800 [initandlisten] targetMinOS: Windows 7/Windows Serv er 2008 R2 2015-05-27T12:44:16.317+0800 [initandlisten] db version v2.6.10 2015-05-27T12:44:16.317+0800 [initandlisten] git version: 5901dbfb49d16eaef6f2c2 c50fba534d23ac7f6c 2015-05-27T12:44:16.317+0800 [initandlisten] build info: windows sys.getwindowsv ersion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49 2015-05-27T12:44:16.317+0800 [initandlisten] allocator: system 2015-05-27T12:44:16.317+0800 [initandlisten] options: { storage: { dbPath: "E:\m ogo_data" } } 2015-05-27T12:44:16.394+0800 [initandlisten] journal dir=E:\mogo_data\journal 2015-05-27T12:44:16.395+0800 [initandlisten] recover begin 2015-05-27T12:44:16.396+0800 [initandlisten] recover lsn: 2659254 2015-05-27T12:44:16.396+0800 [initandlisten] recover E:\mogo_data\journal\j._0 2015-05-27T12:44:16.396+0800 [initandlisten] recover skipping application of sec tion seq:0 < lsn:2659254 2015-05-27T12:44:16.397+0800 [initandlisten] recover skipping application of sec tion seq:59134 < lsn:2659254 2015-05-27T12:44:16.397+0800 [initandlisten] recover skipping application of sec tion seq:118224 < lsn:2659254 2015-05-27T12:44:16.398+0800 [initandlisten] recover skipping application of sec tion seq:177314 < lsn:2659254 2015-05-27T12:44:16.398+0800 [initandlisten] recover skipping application of sec tion seq:236414 < lsn:2659254 2015-05-27T12:44:16.399+0800 [initandlisten] recover skipping application of sec tion seq:295514 < lsn:2659254 2015-05-27T12:44:16.399+0800 [initandlisten] recover skipping application of sec tion seq:354604 < lsn:2659254 2015-05-27T12:44:16.400+0800 [initandlisten] recover skipping application of sec tion seq:413704 < lsn:2659254 2015-05-27T12:44:16.400+0800 [initandlisten] recover skipping application of sec tion seq:472784 < lsn:2659254 2015-05-27T12:44:16.400+0800 [initandlisten] recover skipping application of sec tion more... 2015-05-27T12:44:16.478+0800 [initandlisten] recover cleaning up 2015-05-27T12:44:16.478+0800 [initandlisten] removeJournalFiles 2015-05-27T12:44:16.479+0800 [initandlisten] recover done 2015-05-27T12:44:16.512+0800 [initandlisten] waiting for connections on port 270 17 2015-05-27T12:44:53.407+0800 [initandlisten] connection accepted from 127.0.0.1: 7344 #1 (1 connection now open) 2015-05-27T12:45:16.509+0800 [clientcursormon] mem (MB) res:70 virt:883 2015-05-27T12:45:16.509+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T12:45:16.509+0800 [clientcursormon] connections:1 2015-05-27T12:50:16.528+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T12:50:16.528+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T12:50:16.528+0800 [clientcursormon] connections:1 2015-05-27T12:55:16.547+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T12:55:16.547+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T12:55:16.547+0800 [clientcursormon] connections:1 2015-05-27T13:00:16.569+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:00:16.569+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:00:16.569+0800 [clientcursormon] connections:1 2015-05-27T13:05:16.586+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:05:16.586+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:05:16.586+0800 [clientcursormon] connections:1 2015-05-27T13:10:16.603+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:10:16.603+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:10:16.603+0800 [clientcursormon] connections:1 2015-05-27T13:15:16.620+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:15:16.620+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:15:16.620+0800 [clientcursormon] connections:1 2015-05-27T13:20:16.637+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:20:16.637+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:20:16.637+0800 [clientcursormon] connections:1 2015-05-27T13:25:16.654+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:25:16.654+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:25:16.654+0800 [clientcursormon] connections:1 2015-05-27T13:30:16.671+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:30:16.671+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:30:16.671+0800 [clientcursormon] connections:1 2015-05-27T13:35:16.700+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:35:16.700+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:35:16.700+0800 [clientcursormon] connections:1 2015-05-27T13:40:16.732+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:40:16.732+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:40:16.745+0800 [clientcursormon] connections:1 2015-05-27T13:45:16.775+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:45:16.775+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:45:16.775+0800 [clientcursormon] connections:1 2015-05-27T13:50:16.813+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:50:16.813+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:50:16.816+0800 [clientcursormon] connections:1 2015-05-27T13:51:38.859+0800 [initandlisten] connection accepted from 127.0.0.1: 8203 #2 (2 connections now open) 2015-05-27T13:51:38.869+0800 [conn2] end connection 127.0.0.1:8203 (1 connection now open) 2015-05-27T13:52:06.348+0800 [initandlisten] connection accepted from 127.0.0.1: 8216 #3 (2 connections now open) 2015-05-27T13:52:06.368+0800 [conn3] end connection 127.0.0.1:8216 (1 connection now open) 2015-05-27T13:55:16.849+0800 [clientcursormon] mem (MB) res:70 virt:880 2015-05-27T13:55:16.849+0800 [clientcursormon] mapped (incl journal view):736 2015-05-27T13:55:16.849+0800 [clientcursormon] connections:1 2015-05-27T13:57:03.290+0800 [initandlisten] connection accepted from 127.0.0.1: 8302 #4 (2 connections now open) 2015-05-27T13:57:03.299+0800 [conn4] end connection 127.0.0.1:8302 (1 connection now open) 2015-05-27T13:57:21.789+0800 [initandlisten] connection accepted from 127.0.0.1: 8304 #5 (2 connections now open) 2015-05-27T13:57:21.804+0800 [conn5] end connection 127.0.0.1:8304 (1 connection now open) 2015-05-27T13:57:40.792+0800 [initandlisten] connection accepted from 127.0.0.1: 8308 #6 (2 connections now open) 2015-05-27T13:57:40.809+0800 [conn6] end connection 127.0.0.1:8308 (1 connection now open) 2015-05-27T13:57:54.838+0800 [initandlisten] connection accepted from 127.0.0.1: 8309 #7 (2 connections now open) 2015-05-27T13:57:54.979+0800 [conn7] end connection 127.0.0.1:8309 (1 connection now open) 2015-05-27T13:58:17.267+0800 [initandlisten] connection accepted from 127.0.0.1: 8311 #8 (2 connections now open) 2015-05-27T13:58:17.268+0800 [conn8] CMD: drop test.blog 2015-05-27T13:58:17.271+0800 [conn8] build index on: test.blog properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "test.blog" } 2015-05-27T13:58:17.271+0800 [conn8] added index to empty collection 2015-05-27T13:58:17.277+0800 [conn8] CMD: drop test.fs.chunks 2015-05-27T13:58:17.279+0800 [conn8] build index on: test.fs.chunks properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "test.fs.chunks" } 2015-05-27T13:58:17.280+0800 [conn8] added index to empty collection 2015-05-27T13:58:17.441+0800 [conn8] insert test.fs.chunks ninserted:1 keyUpdate s:0 numYields:0 locks(micros) w:222 120ms 2015-05-27T13:58:17.473+0800 [conn8] build index on: test.fs.chunks properties: { v: 1, unique: true, key: { files_id: 1, n: 1 }, name: "files_id_1_n_1", ns: "t est.fs.chunks" }
二,通过mongodump\mongorestore命令进行备份(热备,服务正常使用)
1,数据导出
[[email protected] ~]# mongodump -h 192.168.60.237 -o /root/test 2015-05-27T13:34:45.737+0800 writing test.fs.chunks to /root/test/test/fs.chunks.bson 2015-05-27T13:34:45.737+0800 writing test.fs.files to /root/test/test/fs.files.bson 2015-05-27T13:34:45.737+0800 writing admin.system.indexes to /root/test/admin/system.indexes.bson 2015-05-27T13:34:45.737+0800 writing test.system.indexes to /root/test/test/system.indexes.bson 2015-05-27T13:34:45.738+0800 writing admin.system.users to /root/test/admin/system.users.bson 2015-05-27T13:34:45.738+0800 writing admin.system.version to /root/test/admin/system.version.bson 2015-05-27T13:34:45.739+0800 writing admin.system.users metadata to /root/test/admin/system.users.metadata.json 2015-05-27T13:34:45.739+0800 writing test.fs.files metadata to /root/test/test/fs.files.metadata.json 2015-05-27T13:34:45.741+0800 writing admin.system.version metadata to /root/test/admin/system.version.metadata.json 2015-05-27T13:34:45.743+0800 done dumping test.fs.files 2015-05-27T13:34:45.743+0800 done dumping admin.system.users 2015-05-27T13:34:45.743+0800 writing test.blog to /root/test/test/blog.bson 2015-05-27T13:34:45.744+0800 done dumping admin.system.version 2015-05-27T13:34:45.744+0800 writing test.blog metadata to /root/test/test/blog.metadata.json 2015-05-27T13:34:45.746+0800 done dumping test.blog 2015-05-27T13:34:45.761+0800 writing test.fs.chunks metadata to /root/test/test/fs.chunks.metadata.json 2015-05-27T13:34:45.762+0800 done dumping test.fs.chunks [[email protected] ~]#
2,数据导入
C:\Program Files\MongoDB 2.6 Standard\bin>mongorestore.exe -d test --directoryp erdb E:\mogo_data2\test --drop 2015-05-27T13:58:17.265+0800 Hotfix KB2731284 or later update is not installed, will zero-out data files connected to: 127.0.0.1 2015-05-27T13:58:17.268+0800 E:\mogo_data2\test\blog.bson 2015-05-27T13:58:17.268+0800 going into namespace [test.blog] 2015-05-27T13:58:17.268+0800 dropping 2015-05-27T13:58:17.271+0800 Created collection test.blog with options: { "cr eate" : "blog" } 1 objects found 2015-05-27T13:58:17.272+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "test.blog" } 2015-05-27T13:58:17.275+0800 E:\mogo_data2\test\fs.chunks.bson 2015-05-27T13:58:17.275+0800 going into namespace [test.fs.chunks] 2015-05-27T13:58:17.276+0800 dropping 2015-05-27T13:58:17.280+0800 Created collection test.fs.chunks with options: { "create" : "fs.chunks" } 271 objects found 2015-05-27T13:58:17.471+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "test.fs.chunks" } 2015-05-27T13:58:17.472+0800 Creating index: { unique: true, key: { files_id: 1, n: 1 }, name: "files_id_1_n_1", ns: "test.fs.chunks" } 2015-05-27T13:58:17.474+0800 E:\mogo_data2\test\fs.files.bson 2015-05-27T13:58:17.475+0800 going into namespace [test.fs.files] 2015-05-27T13:58:17.475+0800 dropping 2015-05-27T13:58:17.480+0800 Created collection test.fs.files with options: { "create" : "fs.files" } 266 objects found 2015-05-27T13:58:17.482+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "test.fs.files" } 2015-05-27T13:58:17.484+0800 Creating index: { key: { filename: 1, uploadDate : 1 }, name: "filename_1_uploadDate_1", ns: "test.fs.files" } 2015-05-27T13:58:17.487+0800 Creating index: { key: { filename: 1 }, name: "_ filename", ns: "test.fs.files" } C:\Program Files\MongoDB 2.6 Standard\bin>
3,通过主从的方式备份,参考本博redhat下mongodb主从配置
略
时间: 2024-11-11 20:39:08