Data Backup and Restore in MySQL
Data Backup
-
Execute the backup command.
docker exec -it $(docker ps | grep community | awk '{print $1}') bash -c 'source /entrypoint.sh && backup mysql'
If successful, the following message will be output (the storage path in the container)
backup mysql saved to /data/backup/20240117130609/mysql
backup log saved to /data/backup/20240117130609/backupMysql.log -
Copy the backup file to the directory in the host (
/data/backup
).mkdir -p /data/backup
docker cp $(docker ps | grep community | awk '{print $1}'):/data/backup/20240117130609 /data/backup/
Data Restore
-
Stop the HAP service. Execute the following command in the root directory of the manager.
bash ./service.sh stopall
-
Remove the original data directory from MySQL (Default:
/data/mingdao/script/volume/data/mysql
).mv /data/mingdao/script/volume/data/mysql /data/backup/mysql_$(date +%Y%m%d%H%M%S)
-
Start the temporary container and mount the data directory (Replaced with the actual mirror address and version number).
- Microservice Version>=5.1.0
- Microservice Version<5.1.0
docker run -it --rm --entrypoint bash -e ENV_MYSQL_HOST="127.0.0.1" -e ENV_MYSQL_PORT="3306" -e ENV_MYSQL_USERNAME="root" -e ENV_MYSQL_PASSWORD="123456" -v /data/mingdao/script/volume/data/:/data/ -v /data/backup/:/data/backup/ registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-sc:3.0.0
docker run -it --rm --entrypoint bash -e ENV_MYSQL_HOST="127.0.0.1" -e ENV_MYSQL_PORT="3306" -e ENV_MYSQL_USERNAME="root" -e ENV_MYSQL_PASSWORD="123456" -v /data/mingdao/script/volume/data/:/data/ -v /data/backup/:/data/backup/ registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-community:version number
-
Create directory.
mkdir -p /data/{logs,mysql}
-
Start MySQL in the temporary container.
source /entrypoint.sh && mysqlStartup &
-
Restore MySQL database (/data/backup/20240117130609/mysql, replaced with actual path).
source /entrypoint.sh && restore mysql /data/backup/20240117130609/mysql
-
Execution completed. Exit the temporary container.
exit