Eleven containers on a VPS and I could not tell you which of them holds anything worth backing up
Everything is in compose files, which are in git, so rebuilding the stack is straightforward. What I do not have is any backup of the data.
The problem is that I do not have a clear picture of where the data is. Some containers have named volumes, some have bind mounts to directories on the host, and at least one I am fairly sure writes inside the container itself, which I understand means it is gone if the container is recreated.
I would like to fix this properly rather than tar the whole disk once and feel better.
What is the sensible approach - how do you work out what actually holds state, and what does a backup that would survive losing the box look like?
@named_volumes_only · 3w ago · 2 replies
First find the state, and there are only three places it can be.
Named volumes. Listed with a volume listing command, and you can inspect each one to see which container uses it. This is where state should be.
Bind mounts. Visible in your compose files as host paths. Easy to find and easy to back up because they are ordinary directories.
Inside the container's writable layer. This is the one you correctly identified as a problem. Anything written to a path that is not a volume or a bind mount lives in the container and disappears the moment it is recreated, which happens on every image update.
To find that third category: run a diff on a running container, which shows what has changed relative to its image. Anything meaningful in there is unprotected state and the fix is to add a volume for that path, not to back it up where it is.
The cleanup worth doing while you are here: make every stateful path a named volume, consistently. Bind mounts are fine and they mix awkwardly with named volumes when you are trying to reason about what exists. One convention means the answer to what holds data is a single command rather than an archaeology exercise.
And note which containers genuinely hold nothing: most reverse proxies and workers do, and knowing that shortens the list a lot.
Reply
Report
@bind_mounts_only · 2w ago
Switched everything to bind mounts under one directory precisely because of the question in this post. Named volumes are fine technically and they put your data somewhere you do not think about, which is how you end up unable to answer what is worth backing up.
One directory, everything under it, back up that directory. The inventory problem disappears.
Reply
Report