I am running several Docker containers on three machines, composing a Swarm cluster.
Some containers that stores persistent data(like DB, Redis, etc) use data volumes. (I tried to avoid using bind-mount as far as I can)
Such data volumes are located in /var/lib/docker/volumes/, and every volumes are assigned customized name rather than random-sequence-ID:
# ls /var/lib/docker/volumes/
redis-data postgres-data fluentd-data ...
I want to backup these volumes periodically, daily for example, so that I could restore when a machine failure occurs and fixed later.
However, every document I found in google illustrated the way to use new Linux container and tar
:
https://docs.docker.com/storage/volumes/#backup-restore-or-migrate-data-volumes
$ docker run --rm --volumes-from dbstore -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata
Why? Is there any problem if I simply archive /var/lib/docker/volumes/VOLUME
directory and copy it to other machine? For example, permission, uid, gid, etc?
$ tar -zcvf redis.tgz /var/lib/docker/volumes/redis-data
P.S.
There would be a case that the backup using tar
could cause data inconsistency due to changes in data during archiving. For example, archiving DB data directory when DB is still running and insert
s or update
s are performed... But I think this problem is applied to both approaches in same way.