Backup and restore the Zero-TOTP database

Backing up your database is important to prevent data loss. You can use the mariadb-dump utility to backup your database.

Backup your database

Note

If you are not using environment variables in docker, make sure to update "$MYSQL_DATABASE" and "$MYSQL_ROOT_PASSWORD".

To backup your database, you can use the following commands on your host :

Database backup command
docker compose exec database /bin/bash -c 'mariadb-dump --databases $MYSQL_DATABASE --user=root    --password=$MYSQL_ROOT_PASSWORD  > /var/lib/mysql/db_backup_$(date +%Y%m%d_%H%M%S).sql'

Warning

Backup location :

  • The backup file will be named db_backup_*.log
  • The backup file will be saved in the /var/lib/mysql directory of the database container which is a mounted volume in your host. Check the mount point in your docker-compose.yml file to find the backup file.

Important

It is highly recommended to copy the backups files into an external filesystem and verify they are not empty !

Restore a database backup

Make sure to mount the backup file into the database container before running the restore command. You can use the /var/lib/mysql mounted volume to copy the backup file into the container. The default path for the mounted volume is $pwd/database/config/.

Note

If you are not using environment variables in docker, make sure to update "$MYSQL_DATABASE" and "$MYSQL_ROOT_PASSWORD".

Restore backup
docker compose exec database /bin/sh -c 'mariadb --user=root --password=$MYSQL_ROOT_PASSWORD < $PATH_TO_SQL_FILE_IN_DOCKER_CONTAINER.sql'
Last updated on