Organize and fix the scripts

This commit is contained in:
Kuba Orlik 2025-10-16 22:58:05 +02:00
parent b509ca1dff
commit 48b0335071
5 changed files with 27 additions and 24 deletions

View File

@ -68,10 +68,15 @@
- initiate
- connection_sanity
- name: Create the backup scripts direct
file:
path: /root/backup-scripts
state: directory
- name: Create the backup vars script
template:
src: "backup-vars.sh.j2"
dest: /root/backup-vars.sh
dest: /root/backup-scripts/vars.sh
mode: "0400"
force: yes
backup: yes
@ -79,7 +84,7 @@
- name: Create the backup send script
template:
src: "backup-send.sh.j2"
dest: /root/backup-send.sh
dest: /root/backup-scripts/send.sh
mode: u+rwx
force: yes
backup: yes
@ -87,7 +92,7 @@
- name: Create the backup mount script
template:
src: "backup-mount.sh.j2"
dest: /root/backup-mount.sh
dest: /root/backup-scripts/mount.sh
mode: u+rwx
force: yes
backup: yes
@ -97,7 +102,7 @@
- name: Create the backup restore script
template:
src: "backup-restore.sh.j2"
dest: /root/backup-restore.sh
dest: /root/backup-scripts/restore.sh
mode: u+rwx
force: yes
backup: yes
@ -105,7 +110,7 @@
- name: Create the backup prepare script
ansible.builtin.template:
src: "backup-scripts/{{inventory_hostname}}.sh.j2"
dest: /root/backup-prepare.sh
dest: /root/backup-scripts/prepare.sh
mode: u+rwx
backup: yes
force: yes
@ -113,7 +118,7 @@
- name: Create is-restore-needed script
ansible.builtin.template:
src: "backup-is-restore-needed.sh.j2"
dest: /root/backup-is-restore-needed.sh
dest: /root/backup-scripts/is-restore-needed.sh
mode: u+rwx
backup: yes
force: yes
@ -121,7 +126,7 @@
- name: Create the backup run script
ansible.builtin.template:
src: "backup-run.sh.j2"
dest: /root/backup-run.sh
dest: /root/backup-scripts/run.sh
mode: u+rwx
backup: yes
force: yes
@ -129,7 +134,7 @@
- name: Create the restore-if-needed script
ansible.builtin.template:
src: "backup-restore-if-necessary.sh.j2"
dest: /root/backup-restore-if-necessary.sh
dest: /root/backup-scripts/restore-if-necessary.sh
mode: u+rwx
backup: yes
force: yes
@ -139,13 +144,13 @@
name: "nightly backup for {{ inventory_hostname }}"
minute: 15
hour: 4
job: "/root/backup-run.sh"
job: "/root/backup-scripts/run.sh"
- name: "Restore backup if necessary"
command: /root/backup-restore-if-necessary.sh
command: /root/backup-scripts/restore-if-necessary.sh
register: command_output
args:
chdir: /root
chdir: /root/backup-scripts
- name: "Print command output"
debug:

View File

@ -1,4 +1,4 @@
source ./backup-vars.sh
source ./vars.sh
MOUNT_PATH="/mnt/restic"

View File

@ -1,7 +1,7 @@
#!/bin/bash
source ./backup-vars.sh;
source ./vars.sh
if ./backup-is-restore-needed.sh; then
./backup-restore.sh
if ./is-restore-needed.sh; then
./restore.sh
fi

View File

@ -2,10 +2,10 @@
original_dir=$(pwd)
source ./backup-vars.sh
source ./vars.sh
cd "$original_dir"
./backup-mount.sh &
./mount.sh &
RESTIC_PID=$!
MOUNT_DIR="/mnt/restic"
@ -25,10 +25,8 @@ done
# Space-separated list of absolute paths
BACKUP_DIR="$MOUNT_DIR/snapshots/latest"
eval "$DIRS_TO_BACKUP_STR" # creates the DIRS_TO_BACKUP array from string
# Iterate over each path in the array
for ORIGINAL_PATH in "${DIRS_TO_BACKUP[@]}"; do
while IFS= read -r ORIGINAL_PATH; do
# Skip empty paths
[[ -z "$ORIGINAL_PATH" ]] && continue
@ -49,7 +47,7 @@ for ORIGINAL_PATH in "${DIRS_TO_BACKUP[@]}"; do
# Use rsync to copy files, preserving permissions, ownership, and timestamps
rsync --archive --acls --xattrs --compress --verbose --human-readable --partial --progress "$BACKUP_PATH/" "$ORIGINAL_PATH/"
done
done </backup-dirs
kill -SIGINT $RESTIC_PID
umount /mnt/restic

View File

@ -2,10 +2,10 @@
original_dir=$(pwd)
source ./backup-vars.sh
source ./vars.sh
cd "$original_dir"
date
source ./backup-prepare.sh
source ./prepare.sh
cd "$original_dir"
date
source ./backup-send.sh
source ./send.sh