Last active
October 4, 2023 14:59
-
-
Save Kambaa/12fe23c5786506ce33ca3b919aceb3a1 to your computer and use it in GitHub Desktop.
Backup volumes of docker-compose services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
THIS SOLUTION ASSUMES THAT YOUR service container has tar installed and to be able to be used! | |
latest update: | |
i wrote 2 commands onmy .bash_profile: | |
checkvol <DOCKER_COMPOSE_SERVICE_NAME> | |
checkvol gitea | |
dockerbackup <DOCKER_COMPOSE_SERVICE_NAME> <DIR_TO_COPY> <FILENAME_TO_COMPRESS> | |
dockerbackup gitea /var/lib/gitea var-lib-gitea-backup.tar.gz | |
i'll post working ones later. | |
-- get container id of a docker compose service by service name: | |
$ docker-compose ps -q your-service-name | |
#docker compose volume destinations list for a given service name (i.e: gitea) | |
#when you have a configuration like this: | |
#... example of gitea service in a docker-compose.yaml file | |
# volumes: | |
# - ./gitea-data:/var/lib/gitea | |
# - ./gitea-config:/etc/gitea | |
#... | |
#this command will give you the output of the volume paths for example: | |
#/var/lib/gitea /etc/gitea | |
$ sudo docker inspect -f '{{range .Mounts}}{{.Destination}} {{end}}' $(sudo docker-compose -f <YOUR_DIR>/docker-compose.yaml ps -q gitea) | |
// for me (my aliases helped me) | |
$ sudo docker inspect -f '{{range .Mounts}}{{.Destination}} {{end}}' $(dc ps -q gitea) | |
# then you can just back them up these directories one by one like this! | |
# your /var/lib/gitea will be compressed to var-lib-gitea-backup.tar.gz file! | |
$ cd <YOUR_BACKUP_DIR> | |
$ dc run --rm -v $(pwd):/backup gitea tar -czvf /backup/var-lib-gitea-backup.tar.gz /var/lib/gitea | |
and | |
# your /etc/gitea will be compressed to etc-gitea-backup.tar.gz file! | |
$ cd <YOUR_BACKUP_DIR> | |
$ dc run --rm -v $(pwd):/backup gitea tar -czvf /backup/etc-gitea-backup.tar.gz /etc/gitea | |
cheers! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment