code: public static void exportToFile(final DatabaseService graphDb, final String fileName, final String query, final boolean includeFiles) throws FrameworkException {
  
  		final App app = StructrApp.getInstance();
  
  		try (final Tx tx = app.tx()) {
  
  			final NodeFactory nodeFactory         = new NodeFactory(SecurityContext.getSuperUserInstance());
  			final RelationshipFactory relFactory  = new RelationshipFactory(SecurityContext.getSuperUserInstance());
  			final Set<AbstractNode> nodes         = new HashSet<>();
  			final Set<AbstractRelationship> rels  = new HashSet<>();
  			boolean conditionalIncludeFiles = includeFiles;
  
  			if (query != null) {
  
  				logger.info("Using Cypher query {} to determine export set, disabling export of files", query);
  
  				conditionalIncludeFiles = false;
  
  				for (final GraphObject obj : StructrApp.getInstance().query(query, null)) {
  
  					if (obj.isNode()) {
  						nodes.add((AbstractNode)obj.getSyncNode());
  					} else {
  						rels.add((AbstractRelationship)obj.getSyncRelationship());
  					}
  				}
  
  				logger.info("Query returned {} nodes and {} relationships.", new Object[] { nodes.size(), rels.size() } );
  
  			} else {
  
  				Iterables.addAll(nodes, nodeFactory.bulkInstantiate(graphDb.getAllNodes()));
  				Iterables.addAll(rels, relFactory.bulkInstantiate(graphDb.getAllRelationships()));
  			}
  
  			try (final FileOutputStream fos = new FileOutputStream(fileName)) {
  
  				exportToStream(fos, nodes, rels, null, conditionalIncludeFiles);
  			}
  
  			tx.success();
  
  		} catch (Throwable t) {
  
  			logger.warn("", t);
  			throw new FrameworkException(500, t.getMessage());
  		}
  
  	}
docs: Exports the whole structr database to a file with the given name.
  
  @param graphDb
  @param fileName
  @param includeFiles
  @throws FrameworkException