mongodb and etcd datastore dump shell scripts


#!/bin/bash



DATABASE_NAME=testdb

function mongo_dump {
    mongo `docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' docker_mongodb_1`:27017 <    use ${DATABASE_NAME}
    print("\n\nmongodb .. dump .. start \n\n");

    db.getCollectionNames().forEach(function(collname) {
        // find the last item in a collection
        var last_element = db[collname].find().sort({_id:-1});
        // check that it's not empty
        if (last_element.hasNext()) {
           // print its timestamp
           printjson(last_element.next());
        }
    })


    print("\n\nmongodb .. dump .. end \n\n");
EOF
}


function etcd_dump() {
    ETCDCTL_API=3 etcdctl --endpoints=`docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' docker_registry_1`:2379 get "" --prefix=true

}




function etcd_cleanup() {
    ETCDCTL_API=3 etcdctl del "" --prefix=true

}