From 881bcc10dbe893f41078b0e3e1e8dbc34e2b32b4 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Tue, 29 Mar 2022 21:20:51 +0200 Subject: [PATCH] Adapted pull primary backups to hardlinks --- .../files/pull-remote-backup.sh | 39 ++++++++++++------- .../templates/ssh-wrapper.sh.j2 | 2 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/roles/native-pull-primary-backups/files/pull-remote-backup.sh b/roles/native-pull-primary-backups/files/pull-remote-backup.sh index 393f1118..17f41f3e 100644 --- a/roles/native-pull-primary-backups/files/pull-remote-backup.sh +++ b/roles/native-pull-primary-backups/files/pull-remote-backup.sh @@ -11,26 +11,35 @@ directories="$(ssh "$source_host" find "$source_path" -maxdepth 1 -type d)" || e for backup_type_dir in $directories; do if [ "$backup_type_dir" != "$source_path" ]; then - # this folder is neccessary to make restricted rsync possible: - current_version="$backup_type_dir/versions/current/" - # this is the folder where the versions will be copied to: - diff_store="$backup_type_dir/versions/$(date '+%Y%m%d%H%M%S')/" - # this is the folder which contains the actual backup: - latest_path="$backup_type_dir/latest/" + # folder which contains versions + versions_dir="$backup_type_dir/versions/" + # link name of last backup + latest_version_link="$backup_type_dir/latest" + # this folder contains the last backup + latest_version_dir="$versions_dir$(date '+%Y%m%d%H%M%S')/" + # this is the link name of the previous version + previous_version_link="$backup_type_dir/previous" # source path of the backup files: - remote_source_path="$source_host:$latest_path" - # file in which the logs will be saved: - log_path="$backup_type_dir/log.txt" + remote_source_path="$source_host:$latest_version_link/" + + #identifiy previous version + versions=( $(basename -a "$versions_dir"*/ | sort) )|| exit 1 + last_version="${versions[-1]}" || exit 1 + previous_version_dir="$versions_dir$last_version/" # create working folders: - mkdir -vp "$latest_path" - mkdir -vp "$diff_store" - rm -vr "$current_version" - mkdir -vp "$current_version" + mkdir -vp "$latest_version_dir" + + # delete links + rm -v "$latest_version_link" + rm -v "$previous_version_link" + + # create links + ln -vs "$latest_version_dir" "$latest_version_link" || exit 1 + ln -vs "$previous_version_dir" "$previous_version_link"|| exit 1 # do backup: - rsync -abP --delete --delete-excluded --rsync-path="sudo rsync" --log-file="$log_path" --backup-dir="$current_version" "$remote_source_path" "$latest_path" || ((errors+=1)); - mv -v "$current_version"* "$diff_store" + rsync -abP --delete --delete-excluded --rsync-path="sudo rsync" --link-dest="$previous_version_link" "$remote_source_path" "$latest_version_link" || ((errors+=1)); fi done exit $errors; diff --git a/roles/native-user-backup/templates/ssh-wrapper.sh.j2 b/roles/native-user-backup/templates/ssh-wrapper.sh.j2 index e9ad8d7f..db4a4d3e 100644 --- a/roles/native-user-backup/templates/ssh-wrapper.sh.j2 +++ b/roles/native-user-backup/templates/ssh-wrapper.sh.j2 @@ -9,7 +9,7 @@ fi # define executable commands hashed_machine_id_command="sha256sum /etc/machine-id"; find_command="find /Backups/{{hashed_machine_id.stdout}}/ -maxdepth 1 -type d"; -rsync_command="sudo rsync --server --sender -blogDtpre.iLsfxCIvu --backup-dir /Backups/{{hashed_machine_id.stdout}}/docker-volume-backup/diffs/current/ . /Backups/{{hashed_machine_id.stdout}}/docker-volume-backup/latest/" +rsync_command="sudo rsync --server --sender -blogDtpre.iLsfxCIvu . /Backups/{{hashed_machine_id.stdout}}/docker-volume-backup/latest" # filter commands case "$SSH_ORIGINAL_COMMAND" in