relayman357
relayman357

Reputation: 855

Move MySQL /var/lib/mysql to shared volume

I'm running a container with MySQL 8.0.18 in Docker on a Synology nas. I'm just using it to support another container (Mediawiki) on that box. MySQL has one volume mounted at path /var/lib/mysql. I would like to move that to a shared volume so i can access it with File Station and also periodically back it up. How can i move it to the docker share shown below without breaking MySQL?

enter image description here

Here are available shares on the Synology nas.

enter image description here

Alternatively, is there a way i can simply copy that /var/lib/mysql to the shared docker folder? That should work as well for periodic backups.

thanks, russ

EDIT: Showing result after following Zeitounator's plan. Before running the docker command (2.) i created the mediawiki_mysql_backups and 12-29-2019 folders in File Station. After running 2. and 3. all the files from mysql are here and i now have a nice backup!

enter image description here

Upvotes: 0

Views: 1244

Answers (1)

Zeitounator
Zeitounator

Reputation: 44615

  1. Stop your current container to make sure mysql is not running.
  2. Create a dummy temp container where you mount the 2 needed volumes. I tend to user busybox for this kind of tasks => docker run -it --rm --name temp_mysql_copy -v mediaviki-mysql:/old-mysql -v /path/to/ttpe/docker:/new-mysql busybox:latest
  3. Copy all files => cp -a /old-mysql/* /new-mysql/
  4. Exit the dummy container (which will cleanup by itself if you used my above command)
  5. Create a new container with mysql:8 image mounting the new folder in /var/lib/mysql (you probably need to do this in your syno docker gui).
  6. If everything works as expected, delete the old mediaviki-mysql volume

Upvotes: 1

Related Questions