Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Official" docker backup strategy - what about consistency?

The suggested strategy to manage and backup data in docker looks something like this:

docker run --name mysqldata -v /var/lib/mysql busybox true
docker run --name mysql --volumes-from mysqldata mysql
docker run --volumes-from mysqldata -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /var/lib/mysql

However, when I backup running containers that way, I won't get a consistent backup, would I? I'm aware of tools like mysqldump, but what if I need to backup, for example, a folder to which files are constantly added and removed?

like image 349
S1lentSt0rm Avatar asked Nov 22 '14 00:11

S1lentSt0rm


People also ask

Can you backup docker containers?

Create a backup Docker containerA new image must be created from the running container to permanently back up the data in the writable layer. The “docker commit” command must be used for this. The contents of the image as a tarball archive must be backed up: Write Docker file system in image.

How do I back up docker volumes?

back up docker data volumes To back up a data volume you can run a new container using the volume you want to back up and executing the tar command to produce an archive of the volume content as described in the docker user guide. In your particular case, the data volume is used to store the data for a MySQL server.

Do containers need backup?

While Docker – and all containers – are typically somewhat newer to a production IT environment than most other technologies, there is still a need to backup these containers, their applications and their persistent data. If a production IT system produces persistent data, that data will likely have some value.


1 Answers

The underlying problem you are facing, i.e. backing up changing files is independent of docker. Use a tool such as rsnapshot or dirvish to make backups into a volume and then use the approach you mentioned above to move those backups to somewhere safer like Amazon s3 or glacier based on your reliability requirement.

Whether you mount volumes from another container or the host vm using the -v switch the changes to the files are reflected in all containers (or host vm) in more or less real-time. (There is some delay because of the AUFS that docker uses on top of host fs, but its not huge). If the backup container was running perpetually it could keep taking backups and the files would always reflect latest files seen by the mysql container.

Edit: For clarity.

like image 191
Usman Ismail Avatar answered Nov 15 '22 07:11

Usman Ismail