mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2024-11-22 00:11:03 +01:00
Highered performance by removing container loop
This commit is contained in:
parent
76d32a2e5c
commit
99f7b387c2
@ -11,32 +11,32 @@ backup_repository_folder="$backups_folder$machine_id/$repository_name/";
|
|||||||
for volume_name in $(docker volume ls --format '{{.Name}}');
|
for volume_name in $(docker volume ls --format '{{.Name}}');
|
||||||
do
|
do
|
||||||
echo "start backup routine: $volume_name";
|
echo "start backup routine: $volume_name";
|
||||||
for container_name in $(docker ps --filter volume="$volume_name" --format '{{.Names}}');
|
containers="$(docker ps --filter volume="$volume_name" --format '{{.Names}}')";
|
||||||
|
containers_array=($containers)
|
||||||
|
container=${containers_array[0]}
|
||||||
|
echo "stop containers: $containers" && docker stop "$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");
|
||||||
do
|
do
|
||||||
echo "stop container: $container_name" && docker stop "$container_name"
|
destination_path="$backup_repository_folder""latest/$volume_name";
|
||||||
for source_path in $(docker inspect --format "{{ range .Mounts }}{{ if eq .Type \"volume\"}}{{ if eq .Name \"$volume_name\"}}{{ println .Destination }}{{ end }}{{ end }}{{ end }}" "$container_name");
|
raw_destination_path="$destination_path/raw"
|
||||||
do
|
prepared_destination_path="$destination_path/prepared"
|
||||||
destination_path="$backup_repository_folder""latest/$volume_name";
|
log_path="$backup_repository_folder""log.txt";
|
||||||
raw_destination_path="$destination_path/raw"
|
backup_dir_path="$backup_repository_folder""diffs/$backup_time/$volume_name";
|
||||||
prepared_destination_path="$destination_path/prepared"
|
raw_backup_dir_path="$backup_dir_path/raw";
|
||||||
log_path="$backup_repository_folder""log.txt";
|
prepared_backup_dir_path="$backup_dir_path/prepared";
|
||||||
backup_dir_path="$backup_repository_folder""diffs/$backup_time/$volume_name";
|
if [ -d "$destination_path" ]
|
||||||
raw_backup_dir_path="$backup_dir_path/raw";
|
then
|
||||||
prepared_backup_dir_path="$backup_dir_path/prepared";
|
echo "backup volume: $volume_name";
|
||||||
if [ -d "$destination_path" ]
|
else
|
||||||
then
|
echo "first backup volume: $volume_name"
|
||||||
echo "backup volume: $volume_name";
|
mkdir -vp "$raw_destination_path";
|
||||||
else
|
mkdir -vp "$raw_backup_dir_path";
|
||||||
echo "first backup volume: $volume_name"
|
mkdir -vp "$prepared_destination_path";
|
||||||
mkdir -vp "$raw_destination_path";
|
mkdir -vp "$prepared_backup_dir_path";
|
||||||
mkdir -vp "$raw_backup_dir_path";
|
fi
|
||||||
mkdir -vp "$prepared_destination_path";
|
docker run --rm --volumes-from "$container" -v "$backups_folder:$backups_folder" "kevinveenbirkenbach/alpine-rsync" sh -c "
|
||||||
mkdir -vp "$prepared_backup_dir_path";
|
rsync -abP --delete --delete-excluded --log-file=$log_path --backup-dir=$raw_backup_dir_path '$source_path/' $raw_destination_path";
|
||||||
fi
|
echo "start containers: $containers" && docker start "$containers";
|
||||||
docker run --rm --volumes-from "$container_name" -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";
|
|
||||||
done
|
|
||||||
echo "start container: $container_name" && docker start "$container_name";
|
|
||||||
done
|
done
|
||||||
echo "end backup routine: $volume_name";
|
echo "end backup routine: $volume_name";
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user