Closed vahidalvandi closed 1 month ago
The top-level volume is specified in compose.yaml. Even if you destroy a container, the data in the volume remains.
volumes:
db-store:
db:
volumes:
- type: volume
source: db-store
target: /var/lib/mysql
volume:
nocopy: true
Is it possible to move the volume to another server? If it is not possible, it is better to save it locally
@vahidalvandi I can't think of any use case where I would like to store the volume on another server. I don't think you should directly touch files under /var/lib/mysql except in special cases. I set it as a volume to prevent users from touching /var/lib/mysql.
If you want to extract MySQL data, I recommend using mysqldump to back up and restore it.
$ docker compose exec db bash -c 'mysqldump --no-tablespaces -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE > /tmp/dump.sql'
$ docker compose cp db:/tmp/dump.sql /tmp/dump.sql
$ docker compose cp /tmp/dump.sql db:/tmp/dump.sql
$ docker compose exec db bash -c 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < /tmp/dump.sql'
$ rm /tmp/dump.sql
i use this container for automatic backup
backup:
image: ghcr.io/realorangeone/db-auto-backup:latest
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./backups:/var/backups
environment:
- SUCCESS_HOOK_URL=
- INCLUDE_LOGS=true
I have considered it, but have no plans to introduce it in this repository.
With this method, the data will not be lost after resetting the container