mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2024-12-23 18:55:03 +01:00
solved pull backup bugs
This commit is contained in:
parent
4bb0de28c8
commit
d721d451e0
@ -25,3 +25,4 @@ To track what the service is doing execute the following command:
|
||||
## see
|
||||
- https://superuser.com/questions/363444/how-do-i-get-the-output-and-exit-value-of-a-subshell-when-using-bash-e
|
||||
- https://gist.github.com/otkrsk/b0ffd4018e8a79b9010c461af298471e
|
||||
- https://serverfault.com/questions/304125/rsync-seems-incompatible-with-bashrc-causes-is-your-shell-clean
|
@ -1,13 +1,24 @@
|
||||
#!/bin/bash
|
||||
# @param $1 hostname from which backup should be pulled
|
||||
|
||||
echo "pulling backups from: $1"
|
||||
|
||||
# error counter
|
||||
errors=0
|
||||
|
||||
echo "loading meta data..."
|
||||
|
||||
remote_host="backup@$1"
|
||||
echo "host address: $remote_host"
|
||||
|
||||
remote_machine_id="$( (ssh "$remote_host" sha256sum /etc/machine-id) | head -c 64 )" || exit 1
|
||||
echo "remote machine id: $remote_machine_id"
|
||||
|
||||
general_backup_machine_dir="/Backups/$remote_machine_id/"
|
||||
remote_backup_types="$(ssh "$remote_host" find "$general_backup_machine_dir" -maxdepth 1 -type d -execdir basename {} ';')" || exit 1
|
||||
echo "backup dir: $general_backup_machine_dir"
|
||||
|
||||
remote_backup_types="$(ssh "$remote_host" "find $general_backup_machine_dir -maxdepth 1 -type d -execdir basename {} ;")" || exit 1
|
||||
echo "backuptypes: $remote_backup_types"
|
||||
|
||||
for backup_type in $remote_backup_types; do
|
||||
if [ "$backup_type" != "$remote_machine_id" ]; then
|
||||
@ -25,11 +36,13 @@ for backup_type in $remote_backup_types; do
|
||||
#identifiy previous version
|
||||
local_versions=( $(basename -a "$general_versions_dir"*/ | sort) )|| exit 1
|
||||
local_last_version="${local_versions[-1]}" || exit 1
|
||||
local_previous_version_dir="$general_versions_dir""$last_version/"
|
||||
local_previous_version_dir="$general_versions_dir""$local_last_version/"
|
||||
|
||||
# source path of the backup files:
|
||||
remote_last_version_dir="$(readlink -f $general_latest_version_link)"
|
||||
remote_last_version_dir="$(ssh "$remote_host" readlink -f $general_latest_version_link)"
|
||||
echo "last remote backup: $remote_last_version_dir"
|
||||
remote_source_path="$remote_host:$remote_last_version_dir/"
|
||||
echo "source path: $remote_source_path"
|
||||
|
||||
# create working folders:
|
||||
mkdir -vp "$local_latest_version_dir"
|
||||
@ -40,10 +53,12 @@ for backup_type in $remote_backup_types; do
|
||||
|
||||
# create links
|
||||
ln -vs "$local_latest_version_dir" "$general_latest_version_link" || exit 1
|
||||
ln -vs "$local_previous_version_dir" "$local_previous_version_link"|| exit 1
|
||||
ln -vs "$local_previous_version_dir" "$local_previous_version_link" || exit 1
|
||||
|
||||
# do backup:
|
||||
rsync -abP --delete --delete-excluded --rsync-path="sudo rsync" --link-dest="$local_previous_version_link" "$remote_source_path" "$general_latest_version_link" || ((errors+=1));
|
||||
rsync_command='rsync -abP --delete --delete-excluded --rsync-path="sudo rsync" --link-dest="'$local_previous_version_link'" "'$remote_source_path'" "'$general_latest_version_link'"'
|
||||
echo "executing: $rsync_command"
|
||||
eval "$rsync_command" || ((errors+=1));
|
||||
fi
|
||||
done
|
||||
exit $errors;
|
||||
|
@ -8,6 +8,7 @@
|
||||
copy:
|
||||
src: pull-remote-backup.sh
|
||||
dest: "{{docker_pull_primary_backups_folder}}pull-remote-backup.sh"
|
||||
mode: 0755
|
||||
|
||||
- name: create pull-remote-backups.service
|
||||
template: src=pull-remote-backups.service.j2 dest=/etc/systemd/system/pull-remote-backups.service
|
||||
@ -18,4 +19,8 @@
|
||||
notify: restart pull-remote-backups timer
|
||||
|
||||
- name: create pull-remote-backups.sh
|
||||
template: src=pull-remote-backups.sh.j2 dest={{docker_pull_primary_backups_folder}}pull-remote-backups.sh
|
||||
template:
|
||||
src: pull-remote-backups.sh.j2
|
||||
dest: "{{docker_pull_primary_backups_folder}}pull-remote-backups.sh"
|
||||
mode: 0755
|
||||
|
||||
|
@ -3,6 +3,6 @@
|
||||
hosts="{{pull_remote_backups_hosts}}";
|
||||
errors=0
|
||||
for host in $hosts; do
|
||||
bash {{docker_pull_primary_backups_folder}}/pull-remote-backup.sh $host || ((errors+=1));
|
||||
bash {{docker_pull_primary_backups_folder}}pull-remote-backup.sh $host || ((errors+=1));
|
||||
done;
|
||||
exit $errors;
|
||||
|
@ -8,10 +8,10 @@ fi
|
||||
|
||||
# define executable commands
|
||||
get_hashed_machine_id="sha256sum /etc/machine-id";
|
||||
get_backup_types="find /Backups/{{hashed_machine_id.stdout}}/ -maxdepth 1 -type d -execdir basename {} ';'";
|
||||
get_backup_types="find /Backups/{{hashed_machine_id.stdout}}/ -maxdepth 1 -type d -execdir basename {} ;";
|
||||
|
||||
# @todo This configuration is not scalable yet. If other backup services then docker-volume-backup are integrated, this logic needs to be optimized
|
||||
get_static_last_version_dir="readlink -f /Backups/{{hashed_machine_id.stdout}}/docker-volume-backup/latest/"
|
||||
get_static_last_version_dir="readlink -f /Backups/{{hashed_machine_id.stdout}}/docker-volume-backup/latest"
|
||||
rsync_command="sudo rsync --server --sender -blogDtpre.iLsfxCIvu . $($get_static_last_version_dir)/"
|
||||
|
||||
# filter commands
|
||||
|
Loading…
Reference in New Issue
Block a user