[containers] Allow database backups via container_name instead of hostname #1116
Labels
No labels
blocked
breaking
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No milestone
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
borgmatic-collective/borgmatic#1116
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'd like to do and why
Currently container database backups are supported by specifying the container name as hostname. This only works if borgmatic is running in the same container network though. My borgmatic runs on the host and I'd like to backup databases from multiple compose apps (which all have their own network). If I could specify
container_nameinstead ofhostnameand let borgmatic run adocker inspect *container_name*to get the IP I would be able to address the container properly. Is this something you would be willing to support -- if yes I can provide the code for it?Other notes / implementation ideas
No response
I'd be willing to support something like this, but I'm not exactly sure how it would work in practice. For instance, as with the current feature for borgmatic running on the host and connecting to a database in a container, container database ports would have to be mapped to the host somehow for borgmatic on the host to be able to connect. Would that be a prerequisite for this proposed feature? And would that port be
inspected as well?Also, instead of connecting to the database by host/port, have you considered dumping directly from a database client running in a container to the host? That might make it easier to just specify a
container_nameand have borgmatic do the right thing.Also note that, as per #685, borgmatic should probably support both Docker and Podman.
No, the port would not need to be mapped and the
docker/podman inspectwould just figure out the IP. Then borgmatic can connect directly to the IP (host services are allowed to connect to all container IPs by default) and the port configured in the config -- so essentially:I haven't not yet tried it because I am a bit afraid of the extra processes in the mix (more complexity). Does that work with all the features (ie streaming directly into the backup). If it works with all the feature then it is probably already 99% what I want. The only problem I see when using the container exec command is that the hostname will be the same, so if I do something like this:
then I will probably have a conflict in the storage names, no?
Thanks for the additional details about the port and IP.
Yes, I believe so, as long as you volume mount the runtime directory as described in the docs.
[...]
You are correct! That would indeed be a problem with this approach.
I'd like to avoid modifying the containers.
Can I read that as an "ok, go ahead with a PR/MR"?
For doing the
container_nameapproach? Sure, a PR would be great. Be aware though that there have been some (hopefully good) dev stack changes since you last submitted a PR.One variant on your implementation idea—and I'll emphasize that I'm just spitballing here—is that instead of a dedicated
container_nameoption, there could be a{container ip ...}interpolation syntax, much like the existing{credential ...}syntax for another use case. Example usage:The idea is that it would allow the container IP to get looked up and plugged in anywhere a hostname was needed in borgmatic's vast config file. So, that means in the hostname option for all other database hooks, all monitoring hooks, etc. And that's without needing (major) changes to any of those hooks to support it.
The downside is that the container name wouldn't be a first-class concept in those hooks. The hooks would only get an IP address for the container and that's it. And then the existing per-hook hostname machinery could go on its merry way using that IP. But that might be enough?
Oh, that is most certainly an interesting idea. The only issue I can see is that container ips are not necessarily stable (container restarts usually keep the ip, but destroying and running a new container might not) leading to a potentially new directory in the backup every time and you might have a hard time to figure out which IP was the correct one :D
One could fix that with a
labeloption to the database backup hooks that would be used to keep a stable name.In the end
{container ip my_postgres_container}and alabelor solely acontainer_nameboth work for me. I think the interpolation is interesting (+label) and looks more powerful. I am not sure how useful it would be for the other hostname options in practice, but it might help?Let me know which approach you'd prefer and I get hacking.
That is a very good point!
Great idea.
Yeah, I could see interpolation +
label:being useful for the other database hooks (except for SQLite). Butlabel:wouldn't be needed for the monitoring hooks, as there's no constructed path stored in the Borg archive for those. (I think the interpolation feature could even be skipped for the monitoring hooks altogether until a need arises.)So I think I have a slight preference for interpolation +
label:over justcontainer_name:, but I don't feel strongly.Thank you!
Hi @witten, I have created a draft PR in #1121 to talk about the design.
What I did for now is adding
label:which is a no-brainer. I then opted forcontainer:instead of an interpolation because the reuse potential seems low and an interpolation might want to allow reading labels etc in the future so we should brainstorm it's design first (like{container label=x container_name}might return the label value of labelxor similar…I also opted to "shell out" and use the docker/podman CLIs. In theory I could call the relevant API endpoints directly but that would:
DOCKER_HOST/DOCKER_CONTEXTwhich the CLI handles out of the boxI would appreciate a "design"-review before I round it up.
This will be part of the next release. Thanks again!
Released in borgmatic 2.0.8!
Thank you, is there a timeline when the docker container with borgmatic will get updated?
That's actually a separate project that other folks manage.. It's usually released with a couple days of a borgmatic release, but it really depends on when they get to it.