bash - Mongodb incremental backups -


i given task setup incremental backups mongodb replicaset, start point of course googled , not find on mongodb docs, did find question encouraged develop own solution didn't find tayra active.

i read oplog , realized easy develop replay log, turns out didn't have mongorestore me.

now have working solution bash scripts , quite easy, that's reason asking here if there flaw in logic, or maybe bite me in future.

below how implemented that:

full backup procedure:

  1. lock writes on secondary member db.fsynclock()
  2. take snapshot
  3. record last position oplog

db.oplog.rs.find().sort({$natural:-1}).limit(1).next().ts

  1. unlock writes db.fsyncunlock()

incremental backup procedure:

  1. lock writes on secondary member
  2. dump oplog recorded oplog position on full (or latest incremental ) backup: mongodump --host <secondary> -d local -c oplog.rs -o /mnt/mongo-test_backup/1 --query '{ "ts" : { $gt : timestamp(1437725201, 50) } }'
  3. record latest oplog position (same way full backups)
  4. unlock writes

full backup restore procedure:

  1. stop instances of mongod
  2. copy snapshot data dir of box primary, make sure exclude local* , mongod.lock restore technique called reconfigure breaking mirror
  3. start primary
  4. reconfigure replicaset
  5. start secondaries without data, let them perform initial sync. or copy data new primary fresh local database

restore incremental backup:

when created incremental backup stored this:

/mnt/mongo-test_backup/1/local/oplog.rs.bson /mnt/mongo-test_backup/1/local/oplog.rs.metadata.json 

we're instered on oplog.rs.bson have rename it, here steps:

  1. change directory backup: cd /mnt/mongo-test_backup/1/local
  2. delete json file rm *.json
  3. rename bson file mv oplog.rs.bson oplog.bson
  4. restore : mongorestore -h <primary> --port <port> --oplogreplay /mnt/mongo-test_backup/1/local

i have scripted, may commit on github later.

question if there flaw in logic. bit suspicious procedure quite straight forward , still couldn't find documented anywhere.


Comments

Post a Comment

Popular posts from this blog

node.js - StackOverflow API not returning JSON -

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -