user17781575
user17781575

Reputation:

How can I backup a Memgraph database?

I'm running a Memgraph within Ubuntu WSL. I want to make a backup of my database. I'm having trouble locating the database files.

I've found the question that addresses Memgraph platform, but I need some solution for WSL.

Upvotes: 2

Views: 252

Answers (1)

user17781575
user17781575

Reputation:

While running, Memgraph generates several different files in its data directory. This is the location where Memgraph saves all permanent data. The default data directory is /var/lib/memgraph.

If you want to trigger creating a snapshot of the current database state, run the following query in mgconsole or Memgraph Lab:

CREATE SNAPSHOT;

Creating a backup of a Memgraph instance would consist of simply copying the data directory. This is impossible without additional help because the durability files can be deleted when an event is triggered (the number of snapshots exceeded the maximum allowed number).

To disable this behavior, you can use the following query in mgconsole or Memgraph Lab:

LOCK DATA DIRECTORY;

If you are using Linux to run Memgraph, here are the steps for copying files:

  1. Start your Memgraph instance.
  2. Open a new Linux terminal and check the location of the permanent data directory:

grep -A 1 'permanent data' /etc/memgraph/memgraph.conf

  1. Copy a file from the snapshot directory to the backup folder, e.g.:

cp /var/lib/memgraph/snapshots/20220325125308366007_timestamp_3380 ~/backup/

To allow the deletion of the files, run the following query in mgconsole or Memgraph Lab::

UNLOCK DATA DIRECTORY;

Memgraph will delete the files which should have been deleted before and allow any future deletion of the files contained in the data directory.

Upvotes: 3

Related Questions