From 3eef4cf70a5ef1f4bda4e1b5146db93c910faec8 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Mon, 12 Oct 2020 13:30:02 +0200 Subject: [PATCH] Optimized destination path --- scripts/backup.sh | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 5b5469f..4b6b3bf 100644 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -9,29 +9,19 @@ do echo "stop container: $docker_container_name" && docker stop "$docker_container_name" for source_path in $(docker inspect --format '{{ range .Mounts }}{{ if eq .Type "volume" }}{{ println .Destination }}{{ end }}{{ end }}' "$docker_container_name"); do - application_path="$docker_backups_mount$(cat /etc/machine-id)/docker/$docker_container_name/" - first_destination_path="$application_path""first""$source_path"; - latest_destination_path="$application_path""latest""$source_path"; - backup_dir_path="$application_path""diffs/$backup_time$source_path" - if [ -d "$native_backups_mount_prefix$first_destination_path" ] + application_path="$docker_backups_mount$(cat /etc/machine-id)/docker/$docker_container_name/"; + destination_path="$application_path""latest""$source_path"; + backup_dir_path="$application_path""diffs/$backup_time$source_path"; + if [ -d "$native_backups_mount_prefix$destination_path" ] then echo "backup: $source_path" - destination_path="$latest_destination_path"; - else echo "first backup: $source_path" - destination_path="$first_destination_path"; - mkdir -vp "$native_backups_mount_prefix$first_destination_path"; - mkdir -vp "$native_backups_mount_prefix$latest_destination_path"; + mkdir -vp "$native_backups_mount_prefix$destination_path"; mkdir -vp "$native_backups_mount_prefix$backup_dir_path"; fi docker run --rm --volumes-from "$docker_container_name" -v "$native_backups_mount:$docker_backups_mount" "kevinveenbirkenbach/alpine-rsync" sh -c " - rsync -ab --delete --delete-excluded --backup-dir=\"$(dirname $backup_dir_path)\" $source_path $destination_path"; - if [ "$destination_path" == "$first_destination_path" ] - then - echo "Cloning first to latest..." - rsync -a "$native_backups_mount_prefix$first_destination_path" "$native_backups_mount_prefix$latest_destination_path" - fi + rsync -ab --delete --delete-excluded --backup-dir=\"$(dirname "$backup_dir_path")\" $source_path $destination_path"; done echo "start container: $docker_container_name" && docker start "$docker_container_name" done