Backup docker container, databases, volumes

I use several docker container on a ZFS filesystem. I would like to backup container, databases, volumes.

My wish-list:

  • Automatic regular backups
  • to another Host to check if backup is working properly
  • if possible incremental

What to backup:

  • container itself
  • databases
  • volumes (less important)

I am using ZFS and docker produces a ton of datasets. I find it difficult to back them up and know afterwards how to put the puzzle pieces of datasets together again.

I managed to find some scripts on github, but wanted to ask here for your experience. I did not find a script which met all my requirements, only partial solutions.

As suggestion to consider, the container its-self should stateless, right? All persistence should be in the defined volume(s). This persistence would include the databases, etc. The idea I would suggest is that you basically have a Dockerfile or scripting that setups up everything from stateless to final state, functional. This is how a typical enterprise solution is designed, that the creation of the container is stateless, then a script or configuration management set up everything, then the data is presented, restored, what have you. Thinking about it, if everything is in the associate volume(s) that is data, whatever it is, that would greatly simplify your total solution. This also leverages the strength of docker, that the container is built on demand when needed.

When you say you find something, are you referring to Dockerfiles?

Why anyone would want to back up anything else than the content of the volume(s) and the compose files required to create the containers? And why are databases mentioned separately? They must be running inside containers, because otherwise their backup would be completely unrelated to docker. If they are running in container: a backup of the volume it is!

Like @jibunnokage wrote: persistent data should not be stored in the container’s file system. Only if persistent data is stored in it, backing it up would make sense… though, fixing the design/configuration problem that requires it to be necessary, would make even more sense.

I don’t think so. If you have a completely stopped database server, you can copy the data, but I would not copy the data under a running database server. Databases have their own backup methods, but that is not really a Docker question, since you would use the same method without containers.