mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-11-24 17:21:03 +01:00
Solved bug concerning non running containers
This commit is contained in:
parent
468f5c60d4
commit
08c961f6e3
@ -15,29 +15,34 @@ do
|
|||||||
containers="$(docker ps --filter volume="$volume_name" --format '{{.Names}}')";
|
containers="$(docker ps --filter volume="$volume_name" --format '{{.Names}}')";
|
||||||
containers_array=($containers)
|
containers_array=($containers)
|
||||||
container=${containers_array[0]}
|
container=${containers_array[0]}
|
||||||
echo "stop containers:" && docker stop $containers
|
if [ -z "$containers" ]
|
||||||
for source_path in $(docker inspect --format "{{ range .Mounts }}{{ if eq .Type \"volume\"}}{{ if eq .Name \"$volume_name\"}}{{ println .Destination }}{{ end }}{{ end }}{{ end }}" "$container");
|
then
|
||||||
do
|
echo "skipped due to no running containers using this volume."
|
||||||
destination_path="$backup_repository_folder""latest/$volume_name";
|
else
|
||||||
raw_destination_path="$destination_path/raw"
|
echo "stop containers:" && docker stop $containers
|
||||||
prepared_destination_path="$destination_path/prepared"
|
for source_path in $(docker inspect --format "{{ range .Mounts }}{{ if eq .Type \"volume\"}}{{ if eq .Name \"$volume_name\"}}{{ println .Destination }}{{ end }}{{ end }}{{ end }}" "$container");
|
||||||
log_path="$backup_repository_folder""log.txt";
|
do
|
||||||
backup_dir_path="$backup_repository_folder""diffs/$backup_time/$volume_name";
|
destination_path="$backup_repository_folder""latest/$volume_name";
|
||||||
raw_backup_dir_path="$backup_dir_path/raw";
|
raw_destination_path="$destination_path/raw"
|
||||||
prepared_backup_dir_path="$backup_dir_path/prepared";
|
prepared_destination_path="$destination_path/prepared"
|
||||||
if [ -d "$destination_path" ]
|
log_path="$backup_repository_folder""log.txt";
|
||||||
then
|
backup_dir_path="$backup_repository_folder""diffs/$backup_time/$volume_name";
|
||||||
echo "backup volume: $volume_name";
|
raw_backup_dir_path="$backup_dir_path/raw";
|
||||||
else
|
prepared_backup_dir_path="$backup_dir_path/prepared";
|
||||||
echo "first backup volume: $volume_name"
|
if [ -d "$destination_path" ]
|
||||||
mkdir -vp "$raw_destination_path";
|
then
|
||||||
mkdir -vp "$raw_backup_dir_path";
|
echo "backup volume: $volume_name";
|
||||||
mkdir -vp "$prepared_destination_path";
|
else
|
||||||
mkdir -vp "$prepared_backup_dir_path";
|
echo "first backup volume: $volume_name"
|
||||||
fi
|
mkdir -vp "$raw_destination_path";
|
||||||
docker run --rm --volumes-from "$container" -v "$backups_folder:$backups_folder" "kevinveenbirkenbach/alpine-rsync" sh -c "
|
mkdir -vp "$raw_backup_dir_path";
|
||||||
rsync -abP --delete --delete-excluded --log-file=$log_path --backup-dir=$raw_backup_dir_path '$source_path/' $raw_destination_path";
|
mkdir -vp "$prepared_destination_path";
|
||||||
echo "start containers:" && docker start $reverse_containers;
|
mkdir -vp "$prepared_backup_dir_path";
|
||||||
done
|
fi
|
||||||
|
docker run --rm --volumes-from "$container" -v "$backups_folder:$backups_folder" "kevinveenbirkenbach/alpine-rsync" sh -c "
|
||||||
|
rsync -abP --delete --delete-excluded --log-file=$log_path --backup-dir=$raw_backup_dir_path '$source_path/' $raw_destination_path";
|
||||||
|
echo "start containers:" && docker start $reverse_containers;
|
||||||
|
done
|
||||||
|
fi
|
||||||
echo "end backup routine: $volume_name";
|
echo "end backup routine: $volume_name";
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user