반응형 데이터베이스9 mongodump and restore with docker mongodump and restore with docker 덤프 ./script phase databasename dump 리스토어 ./script phase databasename restore [me@server001 scripts]$ cat db-backup.sh #!/bin/bash #by catherine.lee MONGO_HOME=/usr/local/mongodb-linux-x86_64-3.4.7 DATE_NOW=`date +"%Y-%m-%d_%H_%M"` BK_HOME=/home/server/backup BK_TAR_NAME=mongo-dump-$DATE_NOW.tar.gz dumpDB() { PHASE=${1} DATABASE=${2} DB_DUMP_DIR=${3} DB_HOST="ser.. 2019. 8. 21. docker mongodump and mongorestore $ sudo docker volume create db_backup a2776236537b5759fbf7be5034a43e7c595a829abd04357fe254a8457b18133e $ sudo docker volume ls | grep db_backup local db_backup docker run시 호스트디렉터리를 마운트해보자. 호스트에는 /catherine/data/backup이라는 디렉터리에는 mongodump 데이터들이 있다. $ sudo docker run --name mongo -it -v /catherine/data/backup/:/db_backups -d mongo:3.6.11 2d64fa268ae0014b466dd0fef656d2772af8f24392a0a321495cd9b9d9c7.. 2019. 8. 19. mongodump and mongorestore 덤프 하고 리스토어 해보자. bla라는 데이터베이스를 덤프 한다. /usr/local/mongodb-linux-x86_64-3.4.7/bin/mongodump -d bla -h alpha-mong-server-host --port 27017 user / password가 있다면 아래처럼 덤프 할수있다. /usr/local/mongodb-linux-x86_64-3.4.7/bin/mongodump -d databasename -h mongodb-server-hostname -u username -p 'password' --authenticationDatabase=admin 덤프시, -o 옵션을 이용해 특정디렉터리에 넣을수있다. 아래는 phase별 데이터베이스를 덤프 와 tar.gz 으로 압축하는 스크립트다... 2019. 8. 19. mongo array map 에 엘리먼트 제거하기 데이터는 이렇게 들어가있음. { "_id" : ObjectId("4qcf2a857d9f8ac73bf43c94"),...... blabla... "type" : "youtube", "youtube" : { "items" : [ { "_id" : ObjectId("4qcf24457d9f8ac73bf43c8e") }, { "_id" : ObjectId("4qcf244d7d9f8ac73bf43c8f") }, { "_id" : ObjectId("4qcf24707d9f8ac73bf43c91") }, { "_id" : ObjectId("4qcf2a457d9f8ac73bf43c93") }, { "_id" : ObjectId("4qcf24c37d9f8ac73bf43c92") } ], "outlink" : false }}.. 2018. 7. 4. mongo mongo_slave_server_host:port database < file.js > dump_users_`date +%Y%m%d`.log mongo file.js$ cat users_find_by_created_at.jsuse users;rs.slaveOk();db.users.find( {"created_at":{$gte: ISODate("2010-01-01T00:00:00Z"), $lte:ISODate("2010-06-01T00:00:00Z")}} ).sort({"created_at":-1}).forEach(function(entry){print("_id = "+entry._id+", gender = "+entry.gender+", birth = "+entry.birthday+", name = "+entry.username + ", phone = "+entry.phone);//print("USER = "+ JSON.stringify(en.. 2018. 7. 3. mongo run javascript file server@server001:~/tmp/by_catherine$ mongo localhost:27017/database_name dump_`date +%Y%m%d`.log localhost:포트/데이터베이스명 print stdout 결과파일 년월일 로그파일 javascript_file.js 파일내용$ cat users_users_dump.js//print("Start");use users;//show collections;rs.slaveOk();//db.users.findOne();//db.users.find({"_id" : ObjectId("55c143ceeb0a190923b5c215")});//db.users.find({"bir.. 2018. 5. 24. mongoexport / mongoimport 하기 mongoexport 하기 1) 원하는 필드만 뽑기users라는 데이터베이스에 users 라는 테이블에서 원하는 필드만 조회해 뽑는다.결과물은 users.json 으로 떨군다.mongoexport -d users -c users —fields _id,email,phone,f_ids -q '{ "state":"enabled" }' --slaveOk=1 —out users.json —port 27016 1-1) 슬레이브Ok=1mongoexport -h servername-num05-mongo3.server.io -d users -c users --fields _id,fids,create_ts -q '{"state":"enabled"}' --slaveOk=1 --out yy0302.json조건절 줘서 데이터 .. 2018. 5. 16. mongodb Unique 인덱스 : 색인된 키에 대해 이미 있거나 중복된 것은 insert되지 않는다 - 복합 인덱스 (Compound Key Index) : 여러개의 key를 기반으로 인데스 생성가능 예) db.things.ensureIndex({age:1, name:-1}); - 희소 인덱스 (Sparse Index) : 색인된 필드만 인덱스 한다 예) db.things.ensureIndex({title:1}, {sparse:true}); 기본은 false - Unique 인덱스 : 색인된 키에 대해 이미 있거나 중복된 것은 insert되지 않는다 예) db.things.ensureIndex({name:1}, {unique: true}); mongos> db.event_participants.createIndex({"user_id":1,"event_name":1},{unique:true})mongos.. 2018. 2. 8. mongoDB 공부중 ( mongodb가이드를 읽고..) 활용가이드와 완벽가이드를 읽고 정리차 끄적인다.. 샤딩..거대한 컬렉션을 클러스터군 서버에 분할해 저장하는 것을 말하고, RDBMS의 파티셔닝과 같은 개념이긴 하지만 몽고는 이를 자동으로 해준다. 몽고에서 샤딩목적은클러스터군을 단일구성인것과 차이가 없게 하고다운타임없이 스케일아웃할수있다.이를 mongos(라우팅 프로세스)가 이를 관장한다. 보통 mongos 뒤에 mongod(클러스터)로 구성한다.mongos는 요청을 클러스터군의 적절한 서버로 전달하고, mongod응답을 취합해 클라이언트에 전달한다. 클러스터..전체데이터중 일부를 책임진다. 분산처리nosql특성처럼 지역성이 중요하다.데이터를 공평하게 분산하기 위해, 일부데이터(샤드)를 샤드간에 이동한다. 어떻게 데이터를 분할하는지 방식이 중요하다.범위기.. 2015. 12. 3. 이전 1 다음 반응형