While running, Memgraph generates various files in the data directory,
including the durability files - snapshots and WAL files that contain Memgraph's
data in a recoverable format. The default data directory is
but you can change it in the main Memgraph configuration
Snapshots are created periodically based on the value defined with the
--storage-snapshot-interval-sec configuration flag in the configuration file.
If you need help adjusting the configuration, check out the how-to guide on
changing the configuration.
To create a backup follow the steps below.
1. Create a snapshot
If necessary, create a snapshot of the current database state by running the
following query in
mgconsole or Memgraph Lab:
2. Lock the data directory
Durability files are deleted when an event is triggered, for example, exceeding the maximum number of snapshots.
To disable this behavior, run the following query in
mgconsole or Memgraph
LOCK DATA DIRECTORY;
3. Copy the data directory and unlock it
Copy the data directory or a single WAL or snapshot file to a backup location.
Copy files if you are using Memgraph on Linux
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
If you are getting a permission error, execute the
sudo su command to get
access privileges and then try to change the working directory again.
Your output should look something like this:
# Path to directory in which to save all permanent data. [string]
As you can see, the path is the default one:
3. Locate the files that you want to backup. Let's say that you want to copy the latest snapshot, list the content of the snapshot directory and then copy the latest file.
ls -l /var/lib/memgraph/snapshots/
-rw-r----- 1 memgraph memgraph 7185673 Mar 25 13:52 20220325125206991975_timestamp_2622
-rw-r----- 1 memgraph memgraph 12521724 Mar 25 13:52 20220325125237040637_timestamp_3028
-rw-r----- 1 memgraph memgraph 17064381 Mar 25 13:53 20220325125308366007_timestamp_3380
4. Copy a file from the snapshot directory to the backup folder:
cp /var/lib/memgraph/snapshots/20220325125308366007_timestamp_3380 ~/backup/
If you need help copying the files from the Docker container, check out the Working with docker guide.
Then, run the following query in
mgconsole or Memgraph Lab to unlock the
UNLOCK DATA DIRECTORY;
Memgraph will delete the files which should have been deleted before locking and allow any future deletion of the durability files.