Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j Community Edition backup in windows

Currently am using Neo4j Community version 1.8.2 with Windows 8. Is it possible to backup the neo4j community version db in windows?

like image 943
yAsH Avatar asked Sep 04 '13 11:09

yAsH


3 Answers

As Pangea said, the official backup tool is only available on Enterprise Edition.

His suggestion of using Windows backup tools isn't a good option unless you know other things about Neo4j. Neo4j doesn't flush information immediately, nor does Lucene, so if you use something like Windows Backup, you will not get the database in a stable backup. You need to either use the Neo4j Backup tool, or you need to shutdown the Graph Database so everything flushes/closes, then backup using Windows.

like image 183
Nicholas Avatar answered Nov 12 '22 01:11

Nicholas


Here are my Powershell scripts for Community edition

#http://stackoverflow.com/questions/1153126/how-to-create-a-zip-archive-with-powershell
function zipFiles()
{
    param(
        [Parameter(Mandatory=$true,Position=0)]$zipfilename
        ,[Parameter(Mandatory=$true,Position=1)]$sourcedir
    )

   Add-Type -Assembly System.IO.Compression.FileSystem
   $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
   [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, $compressionLevel, $false)
}

#http://stackoverflow.com/questions/18612294
function BackupNeo4jCommunity
{
    param(
        [Parameter(Mandatory=$true,Position=0)]$serviceName
        ,[Parameter(Mandatory=$true,Position=1)]$sourceNeoFolder
        ,[Parameter(Mandatory=$true,Position=2)]$zipFilename
    )

    Stop-Service $serviceName

    zipFiles $zipfilename $sourceNeoFolder

    Start-Service $serviceName
}

BackupNeo4jCommunity -serviceName neoWindowsServiceName -sourceNeoFolder "D:\neo4j\myapp\data\graph.db" -zipFilename "D:\Downloads\neo-data.zip"
like image 27
fiat Avatar answered Nov 12 '22 02:11

fiat


Hiyo!

They may work, but neo4j is pretty explicit in their guidance:

By contrast, file system copy-and-paste of databases is not supported [1]

So! Your neo4j install path has a bin folder. In it, you have a neo4j.bat and neo4j-admin.bat. You can use these to stop the database, dump the database in a supported way, and start the database back up.

  • Make sure neo4j*.bat files know where your java is. For example, using the default chocolatey install method, you might have this file structure 'C:\tools\neo4j-community\neo4j-community-VERSION\java\jdkVERSION'. Set a JAVA_HOME environment variable as needed. e.g. in PowerShell, $ENV:JAVA_HOME = 'C:\tools\neo4j-community\neo4j-community-VERSION\java\jdkVERSION'
  • Check if it worked! C:\tools\neo4j-community\neo4j-community-3.2.3\bin\neo4j-admin.bat help. If it failed, you'll get an error message saying something like Invoke-Neo4jAdmin : Could not find java at...
  • It worked? Stop the service, back it up, start the service.

Here's a super simple example; you would want to validate paths, add error handling and so forth.

$ENV:JAVA_HOME = 'C:\tools\neo4j-community\neo4j-community-VERSION\java\jdkVERSION'
C:\tools\neo4j-community\neo4j-community-VERSION\bin\neo4j.bat stop
C:\tools\neo4j-community\neo4j-community-VERSION\bin\neo4j-admin.bat dump --database graph.db --to=C:\temp\neo4j.dump
C:\tools\neo4j-community\neo4j-community-VERSION\bin\neo4j.bat start

This code might change if you have spaces in your path, among other environment variances...

Good luck!

  • [1] https://neo4j.com/docs/operations-manual/current/tools/dump-load
  • [2] https://neo4j.com/docs/operations-manual/current/installation/windows
  • [3] https://neo4j.com/blog/chocolatey-neo4j-windows
like image 22
Cookie Monster Avatar answered Nov 12 '22 01:11

Cookie Monster