mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-09-10 04:25:20 +02:00
removed backup links and versions folder
This commit is contained in:
@@ -1,63 +1,53 @@
|
||||
#!/bin/bash
|
||||
# @param $1 hostname from which backup should be pulled
|
||||
|
||||
echo "pulling backups from: $1"
|
||||
echo "pulling backups from: $1" &&
|
||||
|
||||
# error counter
|
||||
errors=0
|
||||
errors=0 &&
|
||||
|
||||
echo "loading meta data..."
|
||||
echo "loading meta data..." &&
|
||||
|
||||
remote_host="backup@$1"
|
||||
echo "host address: $remote_host"
|
||||
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"
|
||||
remote_machine_id="$( (ssh "$remote_host" sha256sum /etc/machine-id) | head -c 64 )" &&
|
||||
echo "remote machine id: $remote_machine_id" &&
|
||||
|
||||
general_backup_machine_dir="/Backups/$remote_machine_id/"
|
||||
echo "backup dir: $general_backup_machine_dir"
|
||||
general_backup_machine_dir="/Backups/$remote_machine_id/" &&
|
||||
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"
|
||||
remote_backup_types="$(ssh "$remote_host" "find $general_backup_machine_dir -maxdepth 1 -type d -execdir basename {} ;")" &&
|
||||
echo "backup types: $remote_backup_types" || exit 1
|
||||
|
||||
for backup_type in $remote_backup_types; do
|
||||
if [ "$backup_type" != "$remote_machine_id" ]; then
|
||||
general_backup_type_dir="$general_backup_machine_dir""$backup_type/"
|
||||
# folder which contains versions
|
||||
general_versions_dir="$general_backup_type_dir""versions/"
|
||||
# link name of last backup
|
||||
general_latest_version_link="$general_backup_type_dir""latest"
|
||||
echo "backup type: $backup_type" &&
|
||||
|
||||
# this folder contains the last backup
|
||||
local_latest_version_dir="$general_versions_dir$(date '+%Y%m%d%H%M%S')/"
|
||||
# this is the link name of the previous version
|
||||
local_previous_version_link="$general_backup_type_dir""previous"
|
||||
general_backup_type_dir="$general_backup_machine_dir""$backup_type/" &&
|
||||
general_versions_dir="$general_backup_type_dir" &&
|
||||
local_previous_version_dir="$(ls -d $general_versions_dir* | tail -1)" &&
|
||||
echo "last local backup: $local_previous_version_dir" &&
|
||||
|
||||
#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""$local_last_version/"
|
||||
remote_backup_versions="$(ssh "$remote_host" ls -d "$general_backup_type_dir"\*)" &&
|
||||
echo "remote backup versions: $remote_backup_versions" &&
|
||||
|
||||
# source path of the backup files:
|
||||
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"
|
||||
remote_last_backup_dir=$(echo "$remote_backup_versions" | tail -1) &&
|
||||
echo "last remote backup: $remote_last_backup_dir" &&
|
||||
|
||||
# delete links
|
||||
rm -v "$general_latest_version_link"
|
||||
rm -v "$local_previous_version_link"
|
||||
remote_source_path="$remote_host:$remote_last_backup_dir/" &&
|
||||
echo "source path: $remote_source_path" &&
|
||||
|
||||
# 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
|
||||
local_backup_destination_path=$remote_last_backup_dir &&
|
||||
echo "backup destination: $local_backup_destination_path" &&
|
||||
|
||||
# do backup:
|
||||
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"
|
||||
echo "creating local backup destination folder..." &&
|
||||
mkdir -vp "$local_backup_destination_path" &&
|
||||
|
||||
echo "starting backup..." &&
|
||||
rsync_command='rsync -abP --delete --delete-excluded --rsync-path="sudo rsync" --link-dest="'$local_previous_version_dir'" "'$remote_source_path'" "'$local_backup_destination_path'"' &&
|
||||
echo "executing: $rsync_command" &&
|
||||
eval "$rsync_command" || ((errors+=1));
|
||||
fi
|
||||
done
|
||||
|
Reference in New Issue
Block a user