How to persist Memgraph data to local hard drive?
Asked Answered
V

1

6

I am running Memgraph on Windows 11 WSL using this command:

docker run -it -p 7687:7687 -p 3000:3000 -e MEMGRAPH="--bolt-port=7687" -v mg_lib:/mnt/c/temp/memgraph/lib -v mg_log:/mnt/c/temp/memgraph/log  -v mg_etc:/mnt/c/temp/memgraph/etc memgraph

Then I created a node, but I checked and those folders still empty.

How to persist Memgraph data to local hard drive?

Volteface answered 19/10, 2021 at 20:47 Comment(0)
S
7

Memgraph uses two mechanisms to ensure data durability:

  • write-ahead logs (WAL) and
  • periodic snapshots.

Snapshots are taken periodically during the entire runtime of Memgraph. When a snapshot is triggered, the whole data storage is written to the disk. Write-ahead logs save all database modifications that happened to a file. When running Memgraph with Docker, both of these mechanisms rely on the user to create volumes that will store this data when starting Memgraph.

There are two fields to specify for each volume. The first is the name of the volume, and it's unique on a given host machine. In your case, that would be mg_lib, mg_log, and mg_etc. The second field is the path where the file or directory is mounted in the container. In the case of Memgraph, that would be:

  • /var/lib/memgraph (this is where the durability related files are saved)
  • /var/log/memgraph (logs)
  • /etc/memgraph (configuration settings)

Given these paths, the command to run Memgraph with Docker is:

sudo docker run -it -p 7687:7687 -p 3000:3000 -v mg_lib:/var/lib/memgraph -v mg_log:/var/log/memgraph -v mg_etc:/etc/memgraph memgraph

By default, the volumes on the host machine can be found in:

\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes

I hope this answer can provide some clarity.

Sonatina answered 20/10, 2021 at 3:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.