how to dump entire neo4j database - neo4j

Hi guys how to dump entire database i'm using neo4j shell tolls to export entire data he is my query "export-cypher -r -b 10 -o /dump.cypher MATCH (n)<-[r]->(p) return n,r,p
" but few relations are not creating.

You should look at the APOC Procedures plugin for Neo4j. It has export procedures which should accomplish exactly what you need.

Related

How to Load Cypher File into Neo4j

I have generated a cypher file and want to load it into neo4j.
The only relevant documentation I could find was about loading csv's.
I also tried the shell but it seems to have no effect
cypher-shell.bat -uneo4j -pne04j < db.cql
Copy paste into localhost:7474/browser makes the browser unresponsive.
In the current Neo4j version you can use Cypher Shell to achieve your goal.
From the docs, Invoke Cypher Shell with a Cypher script from the command line:
$ cat db.cql | bin/cypher-shell -u yourneo4juser -p yourpassword
Note that this example is based in a Linux instalation. If you are using Neo4j with Windows, you will need to adjust this command to your needs.
Not sure when this has been added but in the current version (4.4) an alternative way to load a cypher file to NEO4J (GUI) is by dragging and dropping the cypher file over the web browser, which then offers two options, either to add it to the favorites or to paste it in the editor.

If neo4j-shell is deprecated then how do I dump the contents of the database (for backup)

I've just been looking into how to backup the database and have found that neo4j-shell -c dump > my-db-dumb.cql looks like a good solution, which exports everything to a cypher query which creates everything when run (a bit like mysqldump for MySQL).
However, according to the official documentation, neo4j-shell has beed deprecated in favour of cypher-shell, and I can't find the equivalent dump function for cypher-shell. Is there one? If not, what should I do instead of neo4j-shell -c dump? Or is there a better way of backing up the database (I have the community edition)? One advantage of the above solution is you don't have to stop the database.
The most useful option is to shutdown the data and then take backups using the new neo4j-admin command.
If you cannot shutdown the graph, then you can manually copy the "graph.db" directory to someplace else, and then use neo4j-shell using the -path option on new location. As far as version 3.1.1 is concerned, the neo4j-shell is working perfectly.

Possible to specify a file of cypher commands with neo4j-shell-tools?

I want to use the neo4j-shell-tools https://github.com/jexp/neo4j-shell-tools because my desired output is a CSV file. With a single Cypher command, this works great, e.g.,
neo4j restart
neo4j-shell
import-cypher -o out.csv match (p) return count(p) as count
However, I actually have a large number of cypher commands saved in a .cql file that I'd like to run. So long as I don't want to export as a CSV file, I can do so via
neo4j-shell -file neatStuff.cql
However, I haven't been able to find a way to combine these, that is, using import-cypher to export the results of a file's worth of Cypher commands.
Does anyone know if this is possible and, if so, how it would be best done? Thank you.
If using multiple commands is not an issue, you can use a pipe. This works on both Unix-based and Windows systems.
echo 'import-cypher -o out.csv match (p) return count(p) as count' | bin/neo4j-shell
neo4j-shell -file neatStuff.cql
Note: the openCypher style guide recommends the .cypher extensions. If you would like to keep is short, use .cyp as .cql is the extensions for the Cassandra Query Language.
Update: as pointed out by the OP in the comments, the latest version of APOC provides apoc.export.csv.* methods.

Batch execute CREATE statements in Cypher / Neo4j

In Neo4j / Cypher: I have a file that contains about 80,000 statements like this one:
create (n:contract {numctr:"35129",CDETYPCTR:"GENERAL",DATDBTCTR:"455407200000",DATTFINCTR:"455407200000"});
I want to import them in my local neo4j server; when I drag the file to the "Drop a file to import Cypher or Grass" area in the neo4j admin, I get a silent failure (nothing is imported, I can't find an error message).
Is there a better way to execute all the statements in my file, like one would do in mysql:
mysql -u username -p database_name < file-to-import.sql
Thanks
Yann
It's almost the same in Neo4j, if you have semicolon separated statements.
It also helps if you put a BEGIN at the beginning and a COMMIT at the end of your 80k statements so that they are all executed in one transaction.
bin/neo4j-shell -file file-to-import.cql
The shell connects to a running server, if you want to create a new datastore you can provide -path path/to/graph.db

neo4j script file format - is there any?

I would like to predefine some graph data for neo4j and be able to load it, maybe via a console tool. I'd like it to be precisely the same as MySQL CLI and .sql files. Does anyone know if there exists a file format like .neo or .neo4j? I couldn't find such thing in the docs...
We usually do .cql or .cypher for script files. You can pipe it to the shell to run it, like so:
./neo4j-shell -c < MY_FILE.cypher
Michael Hunger was doing some great work on this feature, also, just recently. He got performance up and noise down from the console. I hope it gets into 1.9 release.
From https://groups.google.com/forum/#!topic/opencypher/PO5EnspBLs0
1:
"Sorry for the late reply, but we just wanted to inform you that the official recommendation is to use .cypher.
We'll be formalising this in the style guide soon."
2:
"In training run by Neo4j, we've historically used .cyp. I believe the preference is to use .cypher, and .cyp when an extension of 3 chars is required."
3:
"Note: '.cql' is already used for Cassandra - https://cassandra.apache.org/doc/cql/CQL.html"
From the above extracts:
1st preference is .cypher
2nd preference is .cyp (1st 3 characters of cypher)
Don't use .cql
More:
If you need a color coding in notepad++, download the xml given at https://gist.github.com/nicolewhite/b0344ea475852c8c9571 , import it via menu Language > User Defined Language > Import > Restart the Notepad++, open a file with .cypher that has some cyper query language)
Sample cypher is below:
MATCH (:Person {name: "Ann"}) -[:FB_FRIENDS]-> Create (:Person {name: "Dan"})
Hope that helps someone.
Using neo4j-client as the CLI for Neo4j allows for easy evaluation of scripts. There are several ways to work with a script containing multiple cypher commands:
You can pipe the script in via standard input, e.g.:
neo4j-client -u neo4j -P localhost < my_script.cyp
You can use the command line option --source or -i, e.g.:
neo4j-client -u neo4j -P -i my_script.cyp localhost
You can start an interactive shell, and then source the script:
$ neo4j-client localhost
Username: neo4j
Password: *****
neo4j-client 1.2.1.
Enter `:help` for usage hints.
Connected to 'neo4j://neo4j#localhost:7687'
neo4j>
neo4j> :source my_script.cyp
The extension .cyp is most commonly used for scripts.

Resources