Last active
August 29, 2015 14:15
-
-
Save quintessence/e712dbbfffd2357104d8 to your computer and use it in GitHub Desktop.
Trying to restore mongodb from one node to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Scenario: | |
# * Deploy mongodb version 2.6.6 using flocker to node 1 | |
# * Deploy mongodb version 2.6.7 using flocker to node 2 (can use same application.yml) | |
# * Insert v2.6.6 presnapshot data into container on version 2.6.6 | |
# * CURL the API to snapshot v2.6.6 data targeting v2.6.6 container on node 1 | |
# * CURL the API to restore v2.6.6 snapshot to v2.6.7 container on node 2 | |
# * Insert v2.6.6 presnapshot data into container on version 2.6.6 | |
apiHost="http://127.0.0.1:8080" | |
service1Host="172.16.255.250" | |
service1Id="mongo-2.6.6" | |
service2Host="172.16.255.251" | |
service2Id="mongo-2.6.7" | |
mongo1Run() { mongo --quiet ${service1Host}/example --eval "shellPrint($*)"; } | |
mongo2Run() { mongo --quiet ${service2Host}/example --eval "shellPrint($*)"; } | |
api() { curl -X${1} "${apiHost}/$2" 2>/dev/null; } | |
preUpgradeSnapshotData="pre-upgrade-snapshot" | |
echo "Removing all records. Any records listed were not successfully removed." | |
mongo1Run "db.records.remove({})" | |
mongo2Run "db.records.remove({})" | |
mongo1Run "db.records.find({})" | |
mongo2Run "db.records.find({})" | |
echo -e "\nInsert data into the older node and retrieve" | |
mongo1Run "db.records.insert({\"data\": \"${preSnapshotData}\"})" | |
mongo1Run "db.records.find({})" | |
mongo2Run "db.records.find({})" | |
echo -e "\nTake a snapshot." | |
archive=$( | |
api POST "snapshots?host=${service1Host}&name=${service1Id}" | awk -F\" '{print $4}' | |
) | |
echo "archive: ${archive}" | |
echo -e "\nList snapshots should see the snapshot file from above listed." | |
api GET "snapshots" | |
echo -e "\n\nRestore snapshot from older node to newer node" | |
api POST "${api}/snapshots/restore?host=${service2Host}&name=${service2Id}&archive=${archive}" | |
echo -e "\nData should still be on old node..." | |
mongo1Run "db.records.find({})" | |
echo -e "\n...and new node" | |
mongo2Run "db.records.find({})" | |
echo -e "\n\n exit" | |
--- | |
application.yml | |
"version": 1 | |
"applications": | |
"mongo-2.6.6": | |
"image": "clusterhq/mongodb" | |
"ports": | |
- "internal": 27017 | |
"external": 27017 | |
"volume": | |
# The location within the container where the data volume will be | |
# mounted: | |
"mountpoint": "/data/db" | |
"mongo-2.6.7": | |
"image": "clusterhq/mongodb" | |
"ports": | |
- "internal": 27017 | |
"external": 27017 | |
"volume": | |
# The location within the container where the data volume will be | |
# mounted: | |
"mountpoint": "/data/db" | |
--- | |
deployment.yml | |
"version": 1 | |
"nodes": | |
"172.16.255.250": ["mongo-2.6.6"] | |
"172.16.255.251": ["mongo-2.6.7"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment