SlideShare uma empresa Scribd logo
1 de 22
#MongoBoston




Strategies for Backing Up
MongoDB
Jeff Yemin
Engineering Manager, 10gen
File and Directory Layout
• A set of files per database
Insert with write concern of {fsync :
true}
Archive the data directory
Restore the data directory
Start mongod on restored data
directory
Everything is fine, right?
• No, it's not
• But you can't tell until you look
Try validating the collection
• In the shell, run the validate command
How can we get a clean
backup?
• kill mongod
• fsyncLock / fsyncUnlock
How can we get a clean
backup?
• mongodump
mongodump
• Snapshot of each collection
   – Does NOT represent a point in time, even for a single
     collection
• Can NOT be combined with fsyncLock
   – Remember, you can't read…

• You CAN dump directly from data files to get a
 point in time backup
   – mongodump –dbpath

• Can be costlier than archiving as FS level
Snaphot Query

                5

    2                   7


1       3   4       6       8   9
How can we get a clean
backup?
• journaling
Journaling
• Write-ahead log
• Guarantees a consistent view even after a hard
 crash
• Default behavior as of 2.0
• Journal stored in –dbpath /journal folder
• --journalCommitInterval* (2ms - 300ms)
Journaling implications for
backup
• Logical Volume Manager (LVM)
• LVM snapshots to the rescue
   –   lvcreate –size 100M –snapshot –name mdb-snap01 /dev/vg0/mongodb


• No shutdown or fsyncLock needed
• True point in time backup for a single instance
Replica Sets
Backing up a replica set
• Back up a (hidden) secondary
  –   kill mongod
  –   fsyncLock
  –   mongodump
  –   LVM snapshot
Mongodump for replica sets
• True point in time
   – mongodump –oplog
   – mongorestore –-oplogreplay

• Snapshot query of each collection, then replay
 the oplog at the end
   – Similar to how a new secondary does an initial sync
mongos                               config
Chunks!                               balancer
                                                                           config


                                                                           config



  1    2    3    4    13    14   15    16        25    26   27   28   37    38   39   40

  5    6    7    8    17    18   19    20        29    30   31   32   41    42   43   44

  9    10   11   12   21    22   23    24        33    34   35   36   45    46   47   48


      Shard 1              Shard 2                    Shard 3              Shard 4



Sharded clusters
Backing up a sharded cluster

• mongodump through mongos
  – (but no –oplog)

• mongorestore through mongos
Backup a Sharded Cluster
1. Stop Balancer, and wait till inactive (state:0)
      db.settings.update( { _id: "balancer" },
                          { $set : { stopped: true } } , true )
2. Stop a config server Backup Data
  –     Each shard
  –     Config server (mongodump --db config)
3. Restart config server
4. Resume balancer
#MongoBoston




Thank You
Jeff Yemin
Engineering Manager, 10gen

Mais conteúdo relacionado

Mais procurados

Backing Up Data with MMS
Backing Up Data with MMSBacking Up Data with MMS
Backing Up Data with MMSMongoDB
 
Page reclaim
Page reclaimPage reclaim
Page reclaimsiburu
 
Asus WL500gP USB Serial
Asus WL500gP USB SerialAsus WL500gP USB Serial
Asus WL500gP USB Serialguestac21b8
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment StrategyMongoDB
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)MongoDB
 
How to make a WoW server Warlords of Draenor
How to make a WoW server Warlords of DraenorHow to make a WoW server Warlords of Draenor
How to make a WoW server Warlords of DraenorMohit Maheshwari
 
Gns3 0.5 Tutorial
Gns3 0.5 TutorialGns3 0.5 Tutorial
Gns3 0.5 Tutorialrusevi
 
Basics of Logical Replication,Streaming replication vs Logical Replication ,U...
Basics of Logical Replication,Streaming replication vs Logical Replication ,U...Basics of Logical Replication,Streaming replication vs Logical Replication ,U...
Basics of Logical Replication,Streaming replication vs Logical Replication ,U...Rajni Baliyan
 
Qemu上でlagopusを動かした話
Qemu上でlagopusを動かした話Qemu上でlagopusを動かした話
Qemu上でlagopusを動かした話Masaru Oki
 
Wish list from PostgreSQL - Linux Kernel Summit 2009
Wish list from PostgreSQL - Linux Kernel Summit 2009Wish list from PostgreSQL - Linux Kernel Summit 2009
Wish list from PostgreSQL - Linux Kernel Summit 2009Takahiro Itagaki
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016Dave Stokes
 
Nvmfs benchmark
Nvmfs benchmarkNvmfs benchmark
Nvmfs benchmarkLouis liu
 
От sysV к systemd
От sysV к systemdОт sysV к systemd
От sysV к systemdDenis Kovalev
 
MongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-SetMongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-SetVivek Parihar
 
Intro to MySQL Master Slave Replication
Intro to MySQL Master Slave ReplicationIntro to MySQL Master Slave Replication
Intro to MySQL Master Slave Replicationsatejsahu
 
«EC2 без страха»
«EC2 без страха»«EC2 без страха»
«EC2 без страха»Olga Lavrentieva
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storageMarian Marinov
 

Mais procurados (20)

Backing Up Data with MMS
Backing Up Data with MMSBacking Up Data with MMS
Backing Up Data with MMS
 
Page reclaim
Page reclaimPage reclaim
Page reclaim
 
Asus WL500gP USB Serial
Asus WL500gP USB SerialAsus WL500gP USB Serial
Asus WL500gP USB Serial
 
Deployment Strategy
Deployment StrategyDeployment Strategy
Deployment Strategy
 
Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)Deployment Strategies (Mongo Austin)
Deployment Strategies (Mongo Austin)
 
How to make a WoW server Warlords of Draenor
How to make a WoW server Warlords of DraenorHow to make a WoW server Warlords of Draenor
How to make a WoW server Warlords of Draenor
 
Gns3 0.5 Tutorial
Gns3 0.5 TutorialGns3 0.5 Tutorial
Gns3 0.5 Tutorial
 
Basics of Logical Replication,Streaming replication vs Logical Replication ,U...
Basics of Logical Replication,Streaming replication vs Logical Replication ,U...Basics of Logical Replication,Streaming replication vs Logical Replication ,U...
Basics of Logical Replication,Streaming replication vs Logical Replication ,U...
 
Zk meetup talk
Zk meetup talkZk meetup talk
Zk meetup talk
 
Qemu上でlagopusを動かした話
Qemu上でlagopusを動かした話Qemu上でlagopusを動かした話
Qemu上でlagopusを動かした話
 
Wish list from PostgreSQL - Linux Kernel Summit 2009
Wish list from PostgreSQL - Linux Kernel Summit 2009Wish list from PostgreSQL - Linux Kernel Summit 2009
Wish list from PostgreSQL - Linux Kernel Summit 2009
 
MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016MySQL Replication Overview -- PHPTek 2016
MySQL Replication Overview -- PHPTek 2016
 
Nvmfs benchmark
Nvmfs benchmarkNvmfs benchmark
Nvmfs benchmark
 
От sysV к systemd
От sysV к systemdОт sysV к systemd
От sysV к systemd
 
MongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-SetMongoDb scalability and high availability with Replica-Set
MongoDb scalability and high availability with Replica-Set
 
7 Ways To Crash Postgres
7 Ways To Crash Postgres7 Ways To Crash Postgres
7 Ways To Crash Postgres
 
Intro to MySQL Master Slave Replication
Intro to MySQL Master Slave ReplicationIntro to MySQL Master Slave Replication
Intro to MySQL Master Slave Replication
 
Front end development gurant
Front end development gurantFront end development gurant
Front end development gurant
 
«EC2 без страха»
«EC2 без страха»«EC2 без страха»
«EC2 без страха»
 
Comparison of-foss-distributed-storage
Comparison of-foss-distributed-storageComparison of-foss-distributed-storage
Comparison of-foss-distributed-storage
 

Semelhante a Strategies For Backing Up Mongo Db 10.2012 Copy

Webinar: Keeping Your MongoDB Data Safe
Webinar: Keeping Your MongoDB Data SafeWebinar: Keeping Your MongoDB Data Safe
Webinar: Keeping Your MongoDB Data SafeMongoDB
 
MongoDB World 2019: Becoming an Ops Manager Backup Superhero!
MongoDB World 2019: Becoming an Ops Manager Backup Superhero!MongoDB World 2019: Becoming an Ops Manager Backup Superhero!
MongoDB World 2019: Becoming an Ops Manager Backup Superhero!MongoDB
 
MongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and QueueingMongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and QueueingBoxed Ice
 
How to Install and Use MMS
How to Install and Use MMSHow to Install and Use MMS
How to Install and Use MMSMongoDB
 
Benchmarking, Load Testing, and Preventing Terrible Disasters
Benchmarking, Load Testing, and Preventing Terrible DisastersBenchmarking, Load Testing, and Preventing Terrible Disasters
Benchmarking, Load Testing, and Preventing Terrible DisastersMongoDB
 
Let the Tiger Roar!
Let the Tiger Roar!Let the Tiger Roar!
Let the Tiger Roar!MongoDB
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS MongoDB Best Practices in AWS
MongoDB Best Practices in AWS Chris Harris
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)Night Sailer
 
Silicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Silicon Valley Code Camp 2015 - Advanced MongoDB - The SequelSilicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Silicon Valley Code Camp 2015 - Advanced MongoDB - The SequelDaniel Coupal
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDBIgor Donchovski
 
Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Norberto Leite
 
Linux performance tuning & stabilization tips (mysqlconf2010)
Linux performance tuning & stabilization tips (mysqlconf2010)Linux performance tuning & stabilization tips (mysqlconf2010)
Linux performance tuning & stabilization tips (mysqlconf2010)Yoshinori Matsunobu
 
MongoDB开发应用实践
MongoDB开发应用实践MongoDB开发应用实践
MongoDB开发应用实践iammutex
 
Hdlogger project 2014.Aug
Hdlogger project 2014.AugHdlogger project 2014.Aug
Hdlogger project 2014.Aug捷恩 蔡
 
Backup, Restore, and Disaster Recovery
Backup, Restore, and Disaster RecoveryBackup, Restore, and Disaster Recovery
Backup, Restore, and Disaster RecoveryMongoDB
 
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017Codemotion
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentMongoDB
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task QueueRichard Leland
 

Semelhante a Strategies For Backing Up Mongo Db 10.2012 Copy (20)

Webinar: Keeping Your MongoDB Data Safe
Webinar: Keeping Your MongoDB Data SafeWebinar: Keeping Your MongoDB Data Safe
Webinar: Keeping Your MongoDB Data Safe
 
MongoDB World 2019: Becoming an Ops Manager Backup Superhero!
MongoDB World 2019: Becoming an Ops Manager Backup Superhero!MongoDB World 2019: Becoming an Ops Manager Backup Superhero!
MongoDB World 2019: Becoming an Ops Manager Backup Superhero!
 
MongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and QueueingMongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and Queueing
 
How to Install and Use MMS
How to Install and Use MMSHow to Install and Use MMS
How to Install and Use MMS
 
Benchmarking, Load Testing, and Preventing Terrible Disasters
Benchmarking, Load Testing, and Preventing Terrible DisastersBenchmarking, Load Testing, and Preventing Terrible Disasters
Benchmarking, Load Testing, and Preventing Terrible Disasters
 
MongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster RecoveryMongoDB Backup & Disaster Recovery
MongoDB Backup & Disaster Recovery
 
Let the Tiger Roar!
Let the Tiger Roar!Let the Tiger Roar!
Let the Tiger Roar!
 
MongoDB Best Practices in AWS
MongoDB Best Practices in AWS MongoDB Best Practices in AWS
MongoDB Best Practices in AWS
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)
 
Silicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Silicon Valley Code Camp 2015 - Advanced MongoDB - The SequelSilicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Silicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDB
 
Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0Let the Tiger Roar - MongoDB 3.0
Let the Tiger Roar - MongoDB 3.0
 
Linux performance tuning & stabilization tips (mysqlconf2010)
Linux performance tuning & stabilization tips (mysqlconf2010)Linux performance tuning & stabilization tips (mysqlconf2010)
Linux performance tuning & stabilization tips (mysqlconf2010)
 
MongoDB开发应用实践
MongoDB开发应用实践MongoDB开发应用实践
MongoDB开发应用实践
 
Hdlogger project 2014.Aug
Hdlogger project 2014.AugHdlogger project 2014.Aug
Hdlogger project 2014.Aug
 
Backup, Restore, and Disaster Recovery
Backup, Restore, and Disaster RecoveryBackup, Restore, and Disaster Recovery
Backup, Restore, and Disaster Recovery
 
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017
 
DPC Tutorial
DPC TutorialDPC Tutorial
DPC Tutorial
 
Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production Deployment
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
 

Mais de Jeremy Taylor

MongoDB Schema Design -- Inboxes
MongoDB Schema Design -- InboxesMongoDB Schema Design -- Inboxes
MongoDB Schema Design -- InboxesJeremy Taylor
 
TCO - MongoDB vs. Oracle
TCO - MongoDB vs. OracleTCO - MongoDB vs. Oracle
TCO - MongoDB vs. OracleJeremy Taylor
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBJeremy Taylor
 
MongoDB on Windows Azure
MongoDB on Windows AzureMongoDB on Windows Azure
MongoDB on Windows AzureJeremy Taylor
 
MongoDB on Windows Azure
MongoDB on Windows AzureMongoDB on Windows Azure
MongoDB on Windows AzureJeremy Taylor
 
How Apollo Group Evaluted MongoDB
How Apollo Group Evaluted MongoDBHow Apollo Group Evaluted MongoDB
How Apollo Group Evaluted MongoDBJeremy Taylor
 
MongoDB Quick Reference Card
MongoDB Quick Reference CardMongoDB Quick Reference Card
MongoDB Quick Reference CardJeremy Taylor
 
Mongodb Introduction
Mongodb IntroductionMongodb Introduction
Mongodb IntroductionJeremy Taylor
 

Mais de Jeremy Taylor (9)

MongoDB Schema Design -- Inboxes
MongoDB Schema Design -- InboxesMongoDB Schema Design -- Inboxes
MongoDB Schema Design -- Inboxes
 
TCO - MongoDB vs. Oracle
TCO - MongoDB vs. OracleTCO - MongoDB vs. Oracle
TCO - MongoDB vs. Oracle
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
MongoDB on Windows Azure
MongoDB on Windows AzureMongoDB on Windows Azure
MongoDB on Windows Azure
 
MongoDB on Windows Azure
MongoDB on Windows AzureMongoDB on Windows Azure
MongoDB on Windows Azure
 
How Apollo Group Evaluted MongoDB
How Apollo Group Evaluted MongoDBHow Apollo Group Evaluted MongoDB
How Apollo Group Evaluted MongoDB
 
MongoDB Quick Reference Card
MongoDB Quick Reference CardMongoDB Quick Reference Card
MongoDB Quick Reference Card
 
AWS & MongoDB
AWS & MongoDBAWS & MongoDB
AWS & MongoDB
 
Mongodb Introduction
Mongodb IntroductionMongodb Introduction
Mongodb Introduction
 

Strategies For Backing Up Mongo Db 10.2012 Copy

  • 1. #MongoBoston Strategies for Backing Up MongoDB Jeff Yemin Engineering Manager, 10gen
  • 2. File and Directory Layout • A set of files per database
  • 3. Insert with write concern of {fsync : true}
  • 4. Archive the data directory
  • 5. Restore the data directory
  • 6. Start mongod on restored data directory
  • 7. Everything is fine, right? • No, it's not • But you can't tell until you look
  • 8. Try validating the collection • In the shell, run the validate command
  • 9. How can we get a clean backup? • kill mongod • fsyncLock / fsyncUnlock
  • 10. How can we get a clean backup? • mongodump
  • 11. mongodump • Snapshot of each collection – Does NOT represent a point in time, even for a single collection • Can NOT be combined with fsyncLock – Remember, you can't read… • You CAN dump directly from data files to get a point in time backup – mongodump –dbpath • Can be costlier than archiving as FS level
  • 12. Snaphot Query 5 2 7 1 3 4 6 8 9
  • 13. How can we get a clean backup? • journaling
  • 14. Journaling • Write-ahead log • Guarantees a consistent view even after a hard crash • Default behavior as of 2.0 • Journal stored in –dbpath /journal folder • --journalCommitInterval* (2ms - 300ms)
  • 15. Journaling implications for backup • Logical Volume Manager (LVM) • LVM snapshots to the rescue – lvcreate –size 100M –snapshot –name mdb-snap01 /dev/vg0/mongodb • No shutdown or fsyncLock needed • True point in time backup for a single instance
  • 17. Backing up a replica set • Back up a (hidden) secondary – kill mongod – fsyncLock – mongodump – LVM snapshot
  • 18. Mongodump for replica sets • True point in time – mongodump –oplog – mongorestore –-oplogreplay • Snapshot query of each collection, then replay the oplog at the end – Similar to how a new secondary does an initial sync
  • 19. mongos config Chunks! balancer config config 1 2 3 4 13 14 15 16 25 26 27 28 37 38 39 40 5 6 7 8 17 18 19 20 29 30 31 32 41 42 43 44 9 10 11 12 21 22 23 24 33 34 35 36 45 46 47 48 Shard 1 Shard 2 Shard 3 Shard 4 Sharded clusters
  • 20. Backing up a sharded cluster • mongodump through mongos – (but no –oplog) • mongorestore through mongos
  • 21. Backup a Sharded Cluster 1. Stop Balancer, and wait till inactive (state:0) db.settings.update( { _id: "balancer" }, { $set : { stopped: true } } , true ) 2. Stop a config server Backup Data – Each shard – Config server (mongodump --db config) 3. Restart config server 4. Resume balancer

Notas do Editor

  1. Do the fsyncLock/fsyncUnlock demo
  2. i need a picture for the first bullet
  3. Make the point that while you can turn journaling off, you shouldn't.Without journaling, the approach is quite straightforward, there is a one-to-one mapping of data files to memory and when either the OS or an explicit fsync happens, your data is now safe on disk.With journaling we do some tricks.Write ahead log, that is, we write the data to the journal before we update the data itself.Each file is mapped twice, once to a private view which is marked copy-on-write, and once to the shared view – shared in the context that the disk has access to this memory.Every time we do a write, we keep a list of the region of memory that was written to.Batches into group commits, compresses and appends in a group commit to disk by appending to a special journal fileOnce that data has been written to disk, we then do a remapping phase which copies the changes into the shared view, at which point those changes can then be synced to disk.Once that data is synced to disk then it’s safe (barring hardware failure). If there is a failure before the shared/storage view is written to disk, we simply need to apply all the changes in order to the data files since the last time it was synced and we get back to a consistent view of the data
  4. LVM Logical volume manager. LVM is a program that abstracts disk images from physical devices, and provides a number of raw disk manipulation and snapshot capabilities useful for system management.LvcreateThis command creates an LVM snapshot (with the --snapshot option) named mdb-snap01 of the mongodbvolume in the vg0 volume group.This example creates a snapshot named mdb-snap01 located at /dev/vg0/mdb-snap01. The location and paths to your systems volume groups and devices may vary slightly depending on your operating system’sLVM configuration.The snapshot has a cap of at 100 megabytes, because of the parameter --size 100M. This size does not reflect the total amount of the data on the disk, but rather the quantity of differences between the current state of /dev/vg0/mongodb and the creation of the snapshot (i.e. /dev/vg0/mdb-snap01.) Make sure you size this big enough.EBS:If your deployment depends on Amazon’s Elastic Block Storage (EBS) with RAID configured within your instance, it is impossible to get a consistent state across all disks using the platform’s snapshot tool. As a result you may: 1. Flush all writes to disk and create a write lock to ensure consistent state during the backup process. If you choose this option see Backup Without Journaling. 2. Configure LVM to run and hold your MongoDB data files on top of the RAID within your system.If you choose this option, perform the LVM backup operation described in Create Snapshot
  5. If the secondary is hidden, then options are more varied. Killing and locking are valid options, so long as there is enough spare capacity in the system to catch up after the backup is complete
  6. Ok if you have enough space to store all the data on all the shards