nautical-backup icon indicating copy to clipboard operation
nautical-backup copied to clipboard

Extension of the program for Docker volume backup

Open alex1702 opened this issue 1 year ago • 6 comments

Is there a way to extend the program so that the path to Docker volumes (/var/lib/docker/volumes - default path on Linux) can be specified as a source? The idea is to use the Docker API to automatically identify existing volumes so they can be backed up accordingly. It should be possible to control the behavior using labels and environment variables.

I am happy to take a look and try to help implement this as well.

alex1702 avatar Aug 30 '24 17:08 alex1702

You certainly can mount the volume as a source, like this

version: '3'
services:
  nautical-backup:
    image: minituff/nautical-backup:2 
    container_name: nautical-backup
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /config:/config
      - /var/lib/docker/volumes:/app/source  # <--- Updated source
      - /destination:/app/destination

But the problem you will likely run into is the names of the folder do not match the container names. For example:

➜  cd /var/lib/docker/volumes && ll
total 140K
drwx-----x 3 root root   4.0K Aug  9 15:42 02e233612c1c1a0f413b6e46cd2914857dcb16d9fb585cb45b548744f19c1f1a
drwx-----x 3 root root   4.0K Apr 17 17:31 05a38919f1f3c1f5e26b006e199168a96d0f8cf6c3c80c3911c8ca330573d2b8
drwx-----x 3 root root   4.0K Aug  9 15:36 082b03e351489155b82eed3690e3b666a87f15aa1f5219380bbd05873a7a349a
drwx-----x 3 root root   4.0K Apr 14 20:10 1ee71e95e4a917f9e6c86ac3012c5cdcdcda04bfd47f17b9116f8ab5303b8528

You may be able to get away with using the Override Source Definition configs to have them match. But honestly, if we could use the Docker API to get these folder names it would be so much easier. Maybe we could create an environment variable that would enable this feature.

I am happy to take a look and try to help implement this as well.

I'd love that. Your contributions are welcome.

Minituff avatar Aug 30 '24 20:08 Minituff

+1

Akruidenberg avatar Sep 11 '24 12:09 Akruidenberg

+1 for this feature, I love my volumes

StanMar-bit avatar Feb 08 '25 20:02 StanMar-bit

I think it's a good idea to advertise this tool for what it is: backing up bind mounts, not volumes in general. I was kind of disappointed that this project does not support named volumes out of the box.

But honestly, if we could use the Docker API to get these folder names it would be so much easier.

It's possible to get the volume names or absolute paths of the mountpoints of volumes through the docker API and CLI, or am I missing something?

curl --unix-socket /var/run/docker.sock http://localhost/v1.41/containers/prowlarr/json | jq '.Mounts'

This outputs:

[
  {
    "Type": "volume",
    "Name": "prowlarr_data",
    "Source": "/var/lib/docker/volumes/prowlarr_data/_data",
    "Destination": "/config",
    "Driver": "local",
    "Mode": "z",
    "RW": true,
    "Propagation": ""
  }
]

Using the Name or even Source is all your need to start an rsync.

rourke avatar Feb 12 '25 21:02 rourke

@rourke Yeah, totally understand. I can update the readme to make that more clear. When I started developing this app for myself all my containers were using bind mounts so I kind of thought they were synonymous with volumes.

I started on a complete overhaul of the app to support this, but it's becoming a larger update than I thought. I do plan on doing something very similar to what you propose.

Minituff avatar Feb 12 '25 21:02 Minituff

+1, I am starting to use volumes and I can't find a way to backup them nicely!

alexkiddddd avatar May 16 '25 11:05 alexkiddddd