mong 备份和恢复

时间:2024-03-25 14:37:44
[root@hy-mrz01 bin]#  ./mongofiles list -h114.55.5.57 -db pics
20160602152850deeabcb1bd2644afa0c3a9a87e84b36f 124732 [root@hy-mrz01 bin]# ./mongodump -d pics -o /tmp/
connected to: 127.0.0.1
Wed Jul 20 09:23:09.826 DATABASE: pics to /tmp/pics
assertion: 13106 nextSafe(): { $err: "not authorized for query on pics.system.indexes", code: 16550 } 备份mongodb
[root@hy-mrz01 bin]# ./mongodump -u "pics" -p "xxx" -d pics -o /tmp/
connected to: 127.0.0.1
Wed Jul 20 09:24:03.236 DATABASE: pics to /tmp/pics
Wed Jul 20 09:24:03.236 pics.system.indexes to /tmp/pics/system.indexes.bson
Wed Jul 20 09:24:03.237 7 objects
Wed Jul 20 09:24:03.237 pics.system.users to /tmp/pics/system.users.bson
Wed Jul 20 09:24:03.237 1 objects
Wed Jul 20 09:24:03.237 Metadata for pics.system.users to /tmp/pics/system.users.metadata.json
Wed Jul 20 09:24:03.237 pics.fs.files to /tmp/pics/fs.files.bson
Wed Jul 20 09:24:03.239 982 objects
Wed Jul 20 09:24:03.239 Metadata for pics.fs.files to /tmp/pics/fs.files.metadata.json
Wed Jul 20 09:24:03.239 pics.fs.chunks to /tmp/pics/fs.chunks.bson
Wed Jul 20 09:24:04.539 4509 objects
Wed Jul 20 09:24:04.539 Metadata for pics.fs.chunks to /tmp/pics/fs.chunks.metadata.json 恢复mongodb: 数据恢复 mongorestore
./mongorestore -d test /tmp/test --将/tmp/test的数据恢复到test的数据库 新创建mongodb 数据库: 2、安装MongoDB(安装到/usr/local) 复制代码
tar zxvf mongodb-linux-x86_64-2.4.9.tgz
mv mongodb-linux-x86_64-2.4.9 mongodb
cd mongodb
mkdir db
mkdir logs
cd bin
vi mongodb.conf
复制代码
dbpath=/usr/local/mongodb/db
logpath=/usr/local/mongodb/logs/mongodb.log
port=27017
fork=true
nohttpinterface=true
3、重新绑定mongodb的配置文件 /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf
4、开机自动启动mongodb vi /etc/rc.d/rc.local
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf zjtest7-redis:/usr/local/mongodb/bin# ./mongofiles list -db pics
connected to: 127.0.0.1
zjtest7-redis:/usr/local/mongodb/bin# 设置密码:
> use pics;
switched to db pics
>
> db.addUser('pics','1234567');
{
"user" : "pics",
"readOnly" : false,
"pwd" : "ef0dc53a2cae7b91e97e17759a4a9fb6",
"_id" : ObjectId("578ed81ced0931f15e66ec45") 启动认证:
启用的时候需要加--auth /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf --auth zjtest7-redis:/usr/local/mongodb/bin# ps -ef | grep mong
root 1352 1 0 Jul09 ? 00:00:01 /usr/sbin/certmonger -S -p /var/run/certmonger.pid
root 15487 1 0 09:57 ? 00:00:00 /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf --auth
root 15503 15456 0 09:57 pts/2 00:00:00 grep mong
zjtest7-redis:/usr/local/mongodb/bin# mongo
MongoDB shell version: 2.4.9
connecting to: test
> show databases;
admin (empty)
local 0.078125GB
pics 0.203125GB
> use admin;
switched to db admin
> use pics;
switched to db pics
> show tables;
fs.chunks
fs.files
system.indexes
system.users admin数据库也需要设置密码: > use admin;
switched to db admin
> show tables;
> db.addUser('pics','7654321');
{
"user" : "pics",
"readOnly" : false,
"pwd" : "d9f5450932527e4103c64e2b862eae2e",
"_id" : ObjectId("578edacb63eefeb8f9a5b9ac")
} db.auth('pics','1234567') ; db.auth('pics','jh7y,h8l') ; > db.auth('pics','1234567') ;
1
> use pics;
switched to db pics
> show tables;
fs.chunks
fs.files
system.indexes
system.users 导入数据库: 备份mongodb
redis01:/tmp# cd /usr/local/mongodb/bin/
redis01:/usr/local/mongodb/bin# ./mongodump -u "pics" -p "xx" -d pics -o /tmp/
connected to: 127.0.0.1
Wed Jul 20 10:17:41.468 DATABASE: pics to /tmp/pics
Wed Jul 20 10:17:41.469 pics.system.indexes to /tmp/pics/system.indexes.bson
Wed Jul 20 10:17:41.470 8 objects
Wed Jul 20 10:17:41.470 pics.usr to /tmp/pics/usr.bson
Wed Jul 20 10:17:41.470 1 objects
Wed Jul 20 10:17:41.470 Metadata for pics.usr to /tmp/pics/usr.metadata.json
Wed Jul 20 10:17:41.470 pics.fs.files to /tmp/pics/fs.files.bson
Wed Jul 20 10:17:41.473 853 objects
Wed Jul 20 10:17:41.473 Metadata for pics.fs.files to /tmp/pics/fs.files.metadata.json
Wed Jul 20 10:17:41.473 pics.fs.chunks to /tmp/pics/fs.chunks.bson
Wed Jul 20 10:17:42.160 1789 objects
Wed Jul 20 10:17:42.160 Metadata for pics.fs.chunks to /tmp/pics/fs.chunks.metadata.json
Wed Jul 20 10:17:42.160 pics.system.users to /tmp/pics/system.users.bson
Wed Jul 20 10:17:42.160 1 objects
Wed Jul 20 10:17:42.160 Metadata for pics.system.users to /tmp/pics/system.users.metadata.json 恢复mongodb: 数据恢复 mongorestore
./mongorestore -d test /tmp/test --将/tmp/test的数据恢复到test的数据库 demo:/usr/local/mongodb/bin# ./mongorestore -u pics -p '1234567' -d pics /root/pics/ WdJFQl1oR61k84WGuGR_3lhZUjXzd_lJH4GVloj5hTkVJGVVluzDUmRFaS2QXJE_.jpg 121921
2NgUCPM64KFOGoaj63gWhFKywx_0GhRh-18FIHRoL1WbVeoE0ZCxxQ7BvF78-VYp.jpg 77573
r-wTKjCRNJfujhgpS-kDEJLv9lv6mvS0iLsJRSJPOMPZuz0Nyuxd0ZE2q7So6iIY.jpg 62196
demo:/usr/local/mongodb/bin# ./mongofiles list -u'pics' -p'jxxx' -h127.0.0.1 -db pics