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.

_images/didyoubackup.jpg

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

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:

_images/crontab.png

Add this line at the bottom:

00 04 * * * bash /path/to/backup.sh
or
00 04 * * * elabctl backup

This will run the script everyday at 4am.

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 -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
  • uploaded_files-YYYY-MM-DD.zip

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

unzip uploaded_files-YYYY-MM-DD.zip
mv var/elabftw/web/* /var/elabftw/web
mv etc/elabftw.yml /etc/elabftw.yml
# now fix the permissions
chown -R 100: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; # create a new one
Mysql> use elabftw; # select it
Mysql> source mysql_dump-YYYY-MM-DD.sql; # import the backup
Mysql> exit;

Now you should have your old install back :)