How to backup

This page shows you how to backup an existing elabftw installation. It is important that you take the time to make sure that your backups are working properly.


There is basically three things to backup :

  • the MySQL database

  • your config.php file (unless you’re using Docker and you want the /etc/elabftw.yml file)

  • the uploaded files (in uploads/ folder)

Using elabctl

If you installed eLabFTW with elabctl, making a backup becomes very easy. Issue this command as root:

elabctl backup


If you get this error: mysqldump: Error: ‘Access denied; you need (at least one of) the PROCESS privilege(s) for this operation’ when trying to dump tablespaces Update your elabctl with “elabctl self-update” (might need to prepend sudo depending on where you installed it)

Using a script

You’ll want to have a little script that do the backup automatically. Here is one way to do it. Adapt it to your needs: see script.

If you don’t remember your SQL user/password, look in the config.php file!

Make sure to synchronize your files to another computer. Because backuping to the same machine is only half useful.

Making it automatic using cron

A good backup is automatic.

If you’re under a GNU/Linux system, try:

export EDITOR=nano ; crontab -e

This will open a file:


Add this line at the bottom:

00 04 * * * bash /path/to/
00 04 * * * /path/to/elabctl backup

This will run the script everyday at 4am. Make sure to write the full path to elabctl as it might not be in the $PATH for cron.

How to backup a Docker installation

With elabctl

If you installed eLabFTW with elabctl, use:

elabctl backup

Without elabctl

  • Copy the /etc/elabftw.yml somewhere safe.

  • Copy the /var/elabftw folder somewhere safe (make a zip or tar archive).

  • Backup the MySQL database:

docker exec -it mysql bash -c 'mysqldump --no-tablespaces -u$MYSQL_USER -p$MYSQL_PASSWORD -r dump.sql $MYSQL_DATABASE'
docker cp mysql:dump.sql elabftw-$(date --iso-8601).sql
gzip --best elabftw-$(date --iso-8601).sql

How to restore a backup

You should have two files to start with. Those files are the ones generated by elabctl backup command:

  • mysql_dump-YYYY-MM-DD.sql.gz


Let’s start by moving uploaded files and config file at the correct place:

mv var/elabftw/web/* /var/elabftw/web
mv etc/elabftw.yml /etc/elabftw.yml
# now fix the permissions
chown -R 101:101 /var/elabftw/web
chmod 600 /etc/elabftw.yml

Now we import the SQL database (the mysql container must be running):

gunzip mysql_dump-YYYY-MM-DD.sql.gz # uncompress the file
docker cp mysql_dump-YYYY-MM-DD.sql mysql:/ # copy it inside the mysql container
docker exec -it mysql bash # spawn a shell in the mysql container
mysql -uroot -p # login to mysql prompt
# here you type the password you put in MYSQL_ROOT_PASSWORD in the /etc/elabftw.yml file
Mysql> drop database elabftw; # delete the brand new database
Mysql> create database elabftw character set utf8mb4 collate utf8mb4_0900_ai_ci; # create a new one
Mysql> use elabftw; # select it
Mysql> set names utf8; # make sure you import in utf8 (don't do this if you are in latin1)
Mysql> source mysql_dump-YYYY-MM-DD.sql; # import the backup
Mysql> exit;

Now you should have your old install back :)

How to backup a NAS

If you’ve installed elabftw on a NAS, you don’t have elabctl nor a config file. So you’ll need to issue the commands manually (you can make a script after of course).

So the first thing is to create a folder where you’ll put the backups:

export BACKUP_FOLDER=/path/to/your/backup/folder

Next we’ll save the database:

docker exec mysql bash -c 'mysqldump --no-tablespaces -u$MYSQL_USER -p$MYSQL_PASSWORD -r dump.sql $MYSQL_DATABASE'

The environment variables will be correctly replaced; convenient, isn’t it? So just copy paste this and it’ll work.

Next we copy the dump.sql file out of the container, and move it to our backup place:

export DUMP_FILE=${BACKUP_FOLDER}/$(date --iso-8601)-dump.sql
docker cp mysql:dump.sql $DUMP_FILE
# compress it
gzip -f --best $DUMP_FILE

Finally we make a zip of the uploaded files:

export ZIP_FILE=${BACKUP_FOLDER}/$(date --iso-8601)
zip -rq "$ZIP_FILE" /path/to/elabftw/files/web -x /path/to/elabftw/files/web/tmp\*

I’m not sure if you can export the config of the containers from the GUI menu. So maybe take a screenshot or save it manually. Worst case scenario if you lose completely this config it’s not a big deal.

Put all of the above in a script so you can run it easily next time (make a cronjob if possible). See the backup function of elabctl: for inspiration.