-
-
Save xundeenergie/1ad3b5a2545d1a38f802423b75a2ca99 to your computer and use it in GitHub Desktop.
Docker-Compose volume backup
This file contains hidden or 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
#!/bin/bash | |
compose_file_path=$1 | |
project_name=$2 #first part before "_" in container-names. for example nc if container name is nc_cloud | |
backup_path=$3 | |
function backup_volume { | |
volume_name=$1 | |
backup_destination=$2 | |
docker run --rm -v $volume_name:/data -v $backup_destination:/backup ubuntu tar -zcvf /backup/$volume_name.tar /data | |
} | |
echo "Stopping running containers" | |
docker-compose -f $compose_file_path stop | |
echo "Mounting volumes and performing backup..." | |
volumes=($(docker volume ls -f name=$project_name | awk '{if (NR > 1) print $2}')) | |
for v in "${volumes[@]}" | |
do | |
backup_volume $v $backup_path | |
done | |
echo "Restarting containers" | |
docker-compose -f $compose_file_path start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment