Backing Up a Container's Data Volume with One Command
Backing Up a Container’s Data Volume with One Command
Preface
When I first created the miniflux container, I used the official docker-compose.yml
configuration:
1 | services: |
Later, I noticed that the official configuration used a named data volume miniflux-db
. This allows the database directory to be shared between multiple containers, although, in this case, sharing and reading the database directory is unnecessary. However, this has a drawback: if a system failure occurs, there might not be enough time to back up the Docker data volume, or backing it up might be overlooked entirely. The database holds a wealth of RSS links and articles accumulated from long-term subscriptions, forming a valuable dataset that could potentially serve as a knowledge base. Losing this data would be a significant loss.
I researched the issue online. The methods I found were all similar, involving creating a temporary container, mounting the directory, using tar
to create a compressed archive, and then unpacking it with a container. However, after reviewing the Docker commands, I discovered a single-command solution:
1 | docker cp miniflux-db-1:/var/lib/postgresql/data $(pwd)/miniflux-db/ |
This command backs up the data. Create a directory named miniflux-db
in the same location as your docker-compose.yml
file. This will serve as the destination for the backup. In this command, miniflux-db-1
represents the name of your Miniflux database container. Executing this command copies the database contents to the miniflux-db
directory.
Now, you can modify the docker-compose.yml
entry:
1 | db: |
Finally, you can remove the data volume definition from the configuration, as it’s no longer necessary:
1 | volumes: |