mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-09-09 03:37:37 +02:00
implemented new remote backup solution
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
# role native-pull-remote-backups
|
||||
|
||||
## goal
|
||||
This script allows to pull backups from a remote server.
|
||||
|
||||
## scheme
|
||||
It is part of the following scheme:
|
||||
 <br />
|
||||
Further information you will find [in this blog post](https://www.veen.world/2020/12/26/how-i-backup-dedicated-root-servers/).
|
||||
|
||||
## debug
|
||||
|
||||
### live
|
||||
To track what the service is doing execute the following command:
|
||||
|
||||
|
17
roles/native-pull-remote-backups/files/pull-remote-backup.sh
Normal file
17
roles/native-pull-remote-backups/files/pull-remote-backup.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
# @param $1 hostname from which backup should be pulled
|
||||
source_host="backup@$1"
|
||||
source_machine_id="$( (ssh "$source_host" sha256sum /etc/machine-id) | head -c 64)"
|
||||
source_path="/Backups/$source_machine_id/"
|
||||
directories="$(ssh "$source_host" find "$source_path" -maxdepth 1 -type d)"
|
||||
for folder in $directories; do
|
||||
if [ "$folder" != "$source_path" ]; then
|
||||
diff_path="$folder/diffs/$(date '+%Y%m%d%H%M%S')/"
|
||||
latest_path="$folder/latest/"
|
||||
remote_source_path="$source_host:$latest_path"
|
||||
log_path="$folder/log.txt"
|
||||
mkdir -vp "$latest_path"
|
||||
mkdir -vp "$diff_path"
|
||||
rsync -abvv --delete --delete-excluded --rsync-path="sudo rsync" --log-file="$log_path" --backup-dir="$diff_path" "$remote_source_path" "$latest_path" || exit 1
|
||||
fi
|
||||
done
|
@@ -1,16 +1,15 @@
|
||||
- name: pull-remote-backups git
|
||||
git:
|
||||
repo: "https://github.com/kevinveenbirkenbach/pull-remote-backup.git"
|
||||
dest: "/usr/local/bin/pull-remote-backup"
|
||||
update: yes
|
||||
- name: create pull-remote-backup.sh
|
||||
copy:
|
||||
src: pull-remote-backup.sh
|
||||
dest: "/usr/local/bin/pull-remote-backup.sh"
|
||||
|
||||
- name: configure pull-remote-backups.service.tpl
|
||||
- name: create pull-remote-backups.service
|
||||
template: src=pull-remote-backups.service dest=/etc/systemd/system/pull-remote-backups.service
|
||||
notify: restart pull-remote-backups service
|
||||
|
||||
- name: configure pull-remote-backups.timer.tpl
|
||||
- name: create pull-remote-backups.timer
|
||||
template: src=pull-remote-backups.timer dest=/etc/systemd/system/pull-remote-backups.timer
|
||||
notify: restart pull-remote-backups timer
|
||||
|
||||
- name: configure pull-remote-backups.sh
|
||||
template: src=pull-remote-backups.sh dest=/usr/local/bin/pull-remote-backup/pull-remote-backups.sh
|
||||
- name: create pull-remote-backups.sh
|
||||
template: src=pull-remote-backups.sh dest=/usr/local/bin/pull-remote-backups.sh
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#!/bin/bash
|
||||
# Pulls the remote backups from multiple hosts
|
||||
hosts="{{pull_remote_backups_hosts}}";
|
||||
errors=0
|
||||
for host in $hosts; do
|
||||
bash /usr/local/bin/pull-remote-backup/pull-remote-backup.sh $host || ((errors+=1));
|
||||
bash /usr/local/bin/pull-remote-backup.sh $host || ((errors+=1));
|
||||
done;
|
||||
exit $errors;
|
||||
|
Reference in New Issue
Block a user