Narrative
IncyWincyWebApp stores some of its persistent data on MongoDB. Data is
changed for all new insertions, deletions or updates made on documents.
On a supposedly doomed day,
Dave, the developer approaches
Adam, all worried.
Dave: "Hey Adam, looks like something has gone wrong with the data."
Adam: "No worries, We always backup our data to avoid data loss.
Now I will restore it back to make data consistent."
Given source replica set and target node are running
|
with configuration |
source {secureSrcNode} on port {secureSrcPort} , target {secureTgtNode} on port {secureTgtPort} with {username} having {password} |
1. Do Some CUD Operations
run mongo command on |
source |
Comments |
use database |
things |
|
run |
db.createCollection("items") |
|
run |
db.items.insert({name:"One"}) |
|
run |
db.items.save({name:"Two"}) |
|
run |
db.items.save({name:"Three"}) |
|
run |
db.items.remove({name:"One"}) |
|
run |
db.items.update({name:"Three"}, {$set : {name:"Four"}}) |
|
2. Run Backup Utility
Open terminal |
and run |
backup -s {secureSrcNode} --port={secureSrcPort} -f {file} -u admin -p admin |
and show |
stdout |
and ensure |
stdout |
contains |
Process started |
3. Run Restore Utility
Open terminal |
and run |
restore -d {secureTgtNode} --port={secureTgtPort} -f {file} -u admin -p admin |
and show |
stdout |
and show |
stderr |
and ensure |
stdout |
contains |
Process started |
4. Ensure Expected Results
Checking documents of database things
Ensuring target is consistent with source
|
run in database |
things |
query |
db.items.count() |
and cleanup databases |
false |
source value | destination value |
2 | 2 |
Ensuring target is consistent with source
|
find documents for collection |
items |
in database |
things |
where |
null |
and cleanup databases |
true |
source value | destination value |
{ "name" : "Two"} | { "name" : "Two"} |
{ "name" : "Four"} | { "name" : "Four"} |