How to copy DB directory to another Memgraph instance

I have a Memgraph on my desktop with a bund of data. I need that data on my laptop where I have another Memgraph running. How can I do that? Can I just copy the DB directory?


1 Like

Hey @sebastian,

Generally speaking, all database systems don’t like you messing around with their binary data storage whilst they are running.

Memgraph is no exception to that.

So, the destination database must be stopped before copying the data and restarted after the data is copied in order for it to correctly load the data.

The source database doesn’t necessarily need to be stopped, but that is an implementation detail and you risk losing any pending, unflushed data.

The recommendation is always to stop everything while copying the binary data.

If the data is copied into the same directory on the destination server (/var/lib/memgraph) and with the correct permissions, you don’t have to reconfigure anything.

Data (snapshots) directory is defined in Memgraph configuration under --data-directory. By default, the directory is located under /var/lib/memgraph.

I hope this answers your questions!


1 Like

Thank you @Karim.T for quick response! This actually works fine!

How would that work if you’re using the Memgraph Docker image?

Hey @alice24,

This is how it can be done (full process):

  1. Let’s say you have one memgraph running with some data in it (name: memgraph_source)
    docker run --name memgraph_source -p 7687:7687 memgraph:0.50.0
  2. Stop Memgraph (make sure that previous run command does not have flag “–rm” because it will be immediately removed when stopped):
    docker stop memgraph_source
  3. Copy the directory from stopped Docker container to your localhost directory
    docker cp memgraph_source:/var/lib/memgraph
  4. Let’s say there is another memgraph running where you want to move copied data (name: memgraph_target)
    docker run --name memgraph_target -p 7687:7687 memgraph:0.50.0
  5. Stop Memgraph (stop the new one before copying the data):
    docker stop memgraph_target
  6. Copy data to the stopped Memgraph
    docker cp memgraph_target:/var/lib/memgraph
  7. Start Memgraph again
    docker start memgraph_target

[NOTE] Make sure to copy data directories between Memgraph databases with the same version due to backward compatibility.

I hope this helps :smiley: