Narrative
IncyWincyWebApp stores some of its persistent data on MongoDB. Before the
application goes live, Adam, a MongoDB Admin, and Dave, a Developer need
to decide what data needs to be backed up.
Dave: "Adam, We will need all major collections like the
profile in users database, orders within transactions database need to be
backed up".
Dave adding further: "However I see no meaning in
backing up transient collections like sessions and ips in users
database."
Adam: "Yeah Dave, that certainly makes sense, will do the needful!"
Given source replica set and target node are running |
with configuration |
source {unsecureSrcNode} on port {unsecureSrcPort} , target {unsecureTgtNode} on port {unsecureTgtPort} |
1. Do Some CUD Operations
run mongo command on |
source |
Comments |
use database |
users |
|
run |
db.createCollection("profile") |
|
run |
db.profile.insert({name:"One"}) |
|
run |
db.profile.save({name:"Two"}) |
|
run |
db.profile.save({name:"Three"}) |
|
run |
db.profile.remove({name:"One"}) |
|
run |
db.profile.update({name:"Three"}, {$set : {name:"Four"}}) |
|
run |
db.sessions.insert({sessionId:"session1"}) |
|
run |
db.ips.insert({ip:"1.2.3.4"}) |
|
use database |
transactions |
|
run |
db.orders.insert({order:"One"}) |
|
run |
db.orders.save({order:"Two"}) |
|
2. Run Backup Utility
Open terminal |
and run |
backup -s {unsecureSrcNode} --port={unsecureSrcPort} -f {file} --sNs=transactions,users.profile |
and show |
stdout |
and ensure |
stdout |
contains |
Process started |
3. Run Restore Utility
Open terminal |
and run |
restore -d {unsecureTgtNode} --port={unsecureTgtPort} -f {file} |
and show |
stdout |
and ensure |
stdout |
contains |
Process started |
4. Ensure Expected Results
Checking documents of database users
Ensuring target is consistent with source
|
find documents for collection |
profile |
in database |
users |
where |
null |
and cleanup databases |
false |
source value | destination value |
{ "name" : "Two"} | { "name" : "Two"} |
{ "name" : "Four"} | { "name" : "Four"} |
Ensure source and target has
|
run in database |
users |
query |
db.sessions.count() |
and cleanup databases |
false |
source value | destination value |
1 | 0 |
Ensure source and target has
|
run in database |
users |
query |
db.ips.count() |
and cleanup databases |
true |
source value | destination value |
1 | 0 |
Checking documents of database transactions
Ensuring target is consistent with source
|
find documents for collection |
orders |
in database |
transactions |
where |
null |
and cleanup databases |
true |
source value | destination value |
{ "order" : "One"} | { "order" : "One"} |
{ "order" : "Two"} | { "order" : "Two"} |