Search code examples
azuregremlin

Export of a Gremlin database


I would like to know if there is any way to export a Gremlin database with all its vertices/edges. Preferably the output would be a list of Gremlin traversals that can be imported again completely (even partly) if needed.

Does this exist as a tool or within the TinkerPop console client?

Since I am using CosmosDB, I have been trying Azure's Data Migration Tool which does not work for me. Using graphson() did not work for me either, but I might have been using it the wrong way.

gremlin> graph.io(graphson()).writeGraph("/tmp/output.json");
No such property: graph for class: groovysh_evaluate

Solution

  • I'm not aware of any tool that will do this:

    Preferably the output would be a list of Gremlin traversals that can be imported again completely (even partly) if needed.

    All export tools I'm aware of will export to some external format text or binary format. You would have to create such functionality yourself by writing some Gremlin that would return the data in a fashion that would allow you to generate either a String or Bytecode representation of a traversal on the client side. I think you could either export it as an edge list:

    gremlin> g.V().has('person','name','marko').
    ......1>   outE().
    ......2>   project('edgeLabel','weight','inV','outV').
    ......3>     by(label).
    ......4>     by('weight').
    ......5>     by(inV().valueMap(true)).
    ......6>     by(outV().valueMap(true))
    ==>[edgeLabel:created,weight:0.4,inV:[id:3,label:software,name:[lop],lang:[java]],outV:[id:1,label:person,name:[marko],age:[29]]]
    ==>[edgeLabel:knows,weight:0.5,inV:[id:2,label:person,name:[vadas],age:[27]],outV:[id:1,label:person,name:[marko],age:[29]]]
    ==>[edgeLabel:knows,weight:1.0,inV:[id:4,label:person,name:[josh],age:[32]],outV:[id:1,label:person,name:[marko],age:[29]]]
    

    or star graph style:

    gremlin> g.V().has('person','name','marko').
    ......1>   project('v','edges').
    ......2>     by(valueMap(true)).
    ......3>     by(bothE().
    ......4>        project('e','inV','outV').
    ......5>          by(valueMap(true)).
    ......6>          by(valueMap(true)).
    ......7>          by(valueMap(true)))
    ==>[v:[id:1,label:person,name:[marko],age:[29]],edges:[e:[id:9,label:created,weight:0.4],inV:[id:9,label:created,weight:0.4],outV:[id:9,label:created,weight:0.4]]]
    

    The above queries just provide the basic structure. You could come up with better forms, more efficient representations, etc. but the data presented provides all the data you would need to construct traversals on the client side.