7

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

yAsH
  • 3,367
  • 8
  • 36
  • 67

4 Answers4

8

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.

Nicholas
  • 7,403
  • 10
  • 48
  • 76
  • 2
    Good point on the shutdown sequence to ensure all files are flushed, etc. It's worth noting, though, that the snapshot feature is near-instant, minimizing database downtime in the event it's taken offline for snapshotting. Once the snapshot is taken, it may be used for backup purposes even after the Neo4j server has been restarted, as it will be unaffected by the original vhd unless the blob backing the vhd (and related snapshots) are actually deleted. – David Makogon Sep 04 '13 at 19:38
  • Correct, that flush step is important, as neo4j may be unrecoverable if not used. Flushing is the word I was looking for, thanks. – Nicholas Sep 04 '13 at 19:54
  • 1
    I wrote a windows task that runs a bat file that stops the service, copies the data folder to a backup, then restarts the service. Simple enough for a small deployment. – LameCoder Sep 09 '13 at 20:16
2

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"
fiat
  • 15,501
  • 9
  • 81
  • 103
1

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!

Cookie Monster
  • 1,741
  • 1
  • 19
  • 24
0

The Backup service is only available in enterprise edition. You can schedule a regular backup of the Neo4j's data files using the tools that come with Windows.

Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327