mongodb导出导入及备份恢复

1、mongodb导出

test@test:~/桌面$ mongoexport -u test -p -d siyuroom -c userinfo -o userinfo.data
connected to: 127.0.0.1
Enter password: 
exported 15 records

导出为csv
test@test:~/桌面$ mongoexport -utest -p -dsiyuroom -c siyuroom_log --csv -f id,title,logclassid,datetime -o log.csv
connected to: 127.0.0.1
Enter password: 
exported 307 records

2、mongodb导入

test@test:~/桌面$ mongoimport -utest -p123456 -dsiyuroom -cuserinfo userinfo.data
connected to: 127.0.0.1
imported 2 objects
test@test:~/桌面$
导入csv
test@test:~/桌面$ mongoimport -utest -p123456 -dsiyuroom -cuserinfo --type csv --headerline --file=./log.csv 
connected to: 127.0.0.1
imported 308 objects
test@test:~/桌面$
 
3、mongo备份
test@test:~/桌面$ mongodump -uroot -p123456 -d local
connected to: 127.0.0.1
DATABASE: local to dump/local
local.news to dump/local/news.bson
3 objects
local.system.indexes to dump/local/system.indexes.bson
1 objects
test@test:~/桌面$ ls
chrome-pnhechapfaindjhompbnflcldabbghjo-Default.desktop  qq2012-test.desktop
dump                                                     user.data
log.csv                                                  userinfo.data
test@test:~/桌面$ ls -rlht
总用量 36K
-rwx------ 1 test test  220  7月 20 16:12 qq2012-test.desktop
-rwxr-xr-x 1 test test  412 10月  9 13:26 chrome-pnhechapfaindjhompbnflcldabbghjo-Default.desktop
-rw-rw-r-- 1 test test  14K 11月 16 15:32 log.csv
-rw-rw-r-- 1 test test  149 11月 16 15:41 userinfo.data
-rw-rw-r-- 1 test test  149 11月 16 15:41 user.data
drwxrwxr-x 3 test test 4.0K 11月 16 15:48 dump
test@test:~/桌面$ cd dump
test@test:~/桌面/dump$ ls
local
test@test:~/桌面/dump$ cd local
test@test:~/桌面/dump/local$ ls
news.bson  system.indexes.bson
4、mongodb恢复
test@test:~/桌面$ mongorestore -uroot -p123456 -dlocal dump/*
connected to: 127.0.0.1
Sat Nov 16 15:51:03 dump/local/news.bson
Sat Nov 16 15:51:03 going into namespace [local.news]
Sat Nov 16 15:51:03 3 objects found
Sat Nov 16 15:51:03 dump/local/system.indexes.bson
Sat Nov 16 15:51:03 going into namespace [local.system.indexes]
Sat Nov 16 15:51:03 { name: "_id_", ns: "local.news", key: { _id: 1 }, v: 0 }
Sat Nov 16 15:51:03 1 objects found

    A+
发布日期:2021年07月16日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: