FAQ: MySQL database backup and restore procedure (using Docker)
## Prerequisites
1. This procedure is for the Pleasanter database (Implem.Pleasanter) built in Docker using the installation procedure in the user manual.
1. For the backup and restore procedure of a MySQL database installed directly on Linux, please refer to "[FAQ: MySQL database backup and restore procedure](/en/manual/faq-mysql-backup-restore)".
## Overview
If you want to restore to the same environment as the environment in which the backup was taken, please follow the procedure below. In this procedure, the dump file is also output to a folder on the host side so that it can be saved and used outside the container.
## Operation Procedure
1. Backup
2. Restore
### 1. Backup
1. Run the following command to stop the DB container.
```
docker compose stop db
```
2. Add information about the folder and volume where the backup file will be output to compose.yaml. In this procedure, it will be obtained under the /backup directory.
```text
services:
db:
volumes:
- ./backup:/backup ←Add this description.
```
3. Create a folder on the host side to get the backup file.

4. Execute the following command to add the /backup directory to the volume and recreate and restart.
```
docker compose up -d db
```
5. Execute the following command to enter the DB container.
```
docker compose exec db bash
```
6. Execute the command to get the backup file.
```
mysqldump -u root -p Implem.Pleasanter > /backup/Implem.Pleasanter.dump
```
7. Execute the following command to confirm that the backup file was created in the container directory.
```
ls -la /backup/Implem.Pleasanter.dump
```
Example of execution result
`-rw-r--r-- 1 root root 241341 Jul 18 16:50 /backup/Implem.Pleasanter.dump`
8. Verify that the backup file was created in the host folder.

9. Exit the DB container.
```
exit
```
### 2. Restore
1. Run the following command to stop only the pleasanter container.
```
docker compose stop pleasanter
```
2. Run the following command to enter the DB container.
```
docker compose exec db bash
```
3. To be able to switch back after restoration, take a backup with the same command as the backup procedure above.
```
mysqldump -u root -p Implem.Pleasanter > [Output path/file name of backup file to be taken before restoration]
```
4. Log in to the database with the MySQL root account.
```
mysql -u root -p
```
5. Delete and re-create the database (Implem.Pleasanter) with SQL, and log out of the database.
```
drop database `Implem.Pleasanter`;
create database `Implem.Pleasanter` collate utf8mb4_general_ci;
quit;
```
6. Execute the restore command. In this procedure, the database is restored with the backup file under the /backup directory.
```
mysql -u root -p Implem.Pleasanter < /backup/Implem.Pleasanter.dump
```
7. Exit the DB container.
```
exit
```
8. Restart the Pleasanter container.
```
docker compose start pleasanter
```