Organize and fix the scripts
This commit is contained in:
parent
b509ca1dff
commit
48b0335071
@ -68,10 +68,15 @@
|
|||||||
- initiate
|
- initiate
|
||||||
- connection_sanity
|
- connection_sanity
|
||||||
|
|
||||||
|
- name: Create the backup scripts direct
|
||||||
|
file:
|
||||||
|
path: /root/backup-scripts
|
||||||
|
state: directory
|
||||||
|
|
||||||
- name: Create the backup vars script
|
- name: Create the backup vars script
|
||||||
template:
|
template:
|
||||||
src: "backup-vars.sh.j2"
|
src: "backup-vars.sh.j2"
|
||||||
dest: /root/backup-vars.sh
|
dest: /root/backup-scripts/vars.sh
|
||||||
mode: "0400"
|
mode: "0400"
|
||||||
force: yes
|
force: yes
|
||||||
backup: yes
|
backup: yes
|
||||||
@ -79,7 +84,7 @@
|
|||||||
- name: Create the backup send script
|
- name: Create the backup send script
|
||||||
template:
|
template:
|
||||||
src: "backup-send.sh.j2"
|
src: "backup-send.sh.j2"
|
||||||
dest: /root/backup-send.sh
|
dest: /root/backup-scripts/send.sh
|
||||||
mode: u+rwx
|
mode: u+rwx
|
||||||
force: yes
|
force: yes
|
||||||
backup: yes
|
backup: yes
|
||||||
@ -87,7 +92,7 @@
|
|||||||
- name: Create the backup mount script
|
- name: Create the backup mount script
|
||||||
template:
|
template:
|
||||||
src: "backup-mount.sh.j2"
|
src: "backup-mount.sh.j2"
|
||||||
dest: /root/backup-mount.sh
|
dest: /root/backup-scripts/mount.sh
|
||||||
mode: u+rwx
|
mode: u+rwx
|
||||||
force: yes
|
force: yes
|
||||||
backup: yes
|
backup: yes
|
||||||
@ -97,7 +102,7 @@
|
|||||||
- name: Create the backup restore script
|
- name: Create the backup restore script
|
||||||
template:
|
template:
|
||||||
src: "backup-restore.sh.j2"
|
src: "backup-restore.sh.j2"
|
||||||
dest: /root/backup-restore.sh
|
dest: /root/backup-scripts/restore.sh
|
||||||
mode: u+rwx
|
mode: u+rwx
|
||||||
force: yes
|
force: yes
|
||||||
backup: yes
|
backup: yes
|
||||||
@ -105,7 +110,7 @@
|
|||||||
- name: Create the backup prepare script
|
- name: Create the backup prepare script
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: "backup-scripts/{{inventory_hostname}}.sh.j2"
|
src: "backup-scripts/{{inventory_hostname}}.sh.j2"
|
||||||
dest: /root/backup-prepare.sh
|
dest: /root/backup-scripts/prepare.sh
|
||||||
mode: u+rwx
|
mode: u+rwx
|
||||||
backup: yes
|
backup: yes
|
||||||
force: yes
|
force: yes
|
||||||
@ -113,7 +118,7 @@
|
|||||||
- name: Create is-restore-needed script
|
- name: Create is-restore-needed script
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: "backup-is-restore-needed.sh.j2"
|
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
|
mode: u+rwx
|
||||||
backup: yes
|
backup: yes
|
||||||
force: yes
|
force: yes
|
||||||
@ -121,7 +126,7 @@
|
|||||||
- name: Create the backup run script
|
- name: Create the backup run script
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: "backup-run.sh.j2"
|
src: "backup-run.sh.j2"
|
||||||
dest: /root/backup-run.sh
|
dest: /root/backup-scripts/run.sh
|
||||||
mode: u+rwx
|
mode: u+rwx
|
||||||
backup: yes
|
backup: yes
|
||||||
force: yes
|
force: yes
|
||||||
@ -129,7 +134,7 @@
|
|||||||
- name: Create the restore-if-needed script
|
- name: Create the restore-if-needed script
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: "backup-restore-if-necessary.sh.j2"
|
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
|
mode: u+rwx
|
||||||
backup: yes
|
backup: yes
|
||||||
force: yes
|
force: yes
|
||||||
@ -139,13 +144,13 @@
|
|||||||
name: "nightly backup for {{ inventory_hostname }}"
|
name: "nightly backup for {{ inventory_hostname }}"
|
||||||
minute: 15
|
minute: 15
|
||||||
hour: 4
|
hour: 4
|
||||||
job: "/root/backup-run.sh"
|
job: "/root/backup-scripts/run.sh"
|
||||||
|
|
||||||
- name: "Restore backup if necessary"
|
- name: "Restore backup if necessary"
|
||||||
command: /root/backup-restore-if-necessary.sh
|
command: /root/backup-scripts/restore-if-necessary.sh
|
||||||
register: command_output
|
register: command_output
|
||||||
args:
|
args:
|
||||||
chdir: /root
|
chdir: /root/backup-scripts
|
||||||
|
|
||||||
- name: "Print command output"
|
- name: "Print command output"
|
||||||
debug:
|
debug:
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
source ./backup-vars.sh
|
source ./vars.sh
|
||||||
|
|
||||||
MOUNT_PATH="/mnt/restic"
|
MOUNT_PATH="/mnt/restic"
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source ./backup-vars.sh;
|
source ./vars.sh
|
||||||
|
|
||||||
if ./backup-is-restore-needed.sh; then
|
if ./is-restore-needed.sh; then
|
||||||
./backup-restore.sh
|
./restore.sh
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
original_dir=$(pwd)
|
original_dir=$(pwd)
|
||||||
|
|
||||||
source ./backup-vars.sh
|
source ./vars.sh
|
||||||
cd "$original_dir"
|
cd "$original_dir"
|
||||||
|
|
||||||
./backup-mount.sh &
|
./mount.sh &
|
||||||
RESTIC_PID=$!
|
RESTIC_PID=$!
|
||||||
|
|
||||||
MOUNT_DIR="/mnt/restic"
|
MOUNT_DIR="/mnt/restic"
|
||||||
@ -25,10 +25,8 @@ done
|
|||||||
# Space-separated list of absolute paths
|
# Space-separated list of absolute paths
|
||||||
BACKUP_DIR="$MOUNT_DIR/snapshots/latest"
|
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
|
# 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
|
# Skip empty paths
|
||||||
[[ -z "$ORIGINAL_PATH" ]] && continue
|
[[ -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
|
# Use rsync to copy files, preserving permissions, ownership, and timestamps
|
||||||
rsync --archive --acls --xattrs --compress --verbose --human-readable --partial --progress "$BACKUP_PATH/" "$ORIGINAL_PATH/"
|
rsync --archive --acls --xattrs --compress --verbose --human-readable --partial --progress "$BACKUP_PATH/" "$ORIGINAL_PATH/"
|
||||||
done
|
done </backup-dirs
|
||||||
|
|
||||||
kill -SIGINT $RESTIC_PID
|
kill -SIGINT $RESTIC_PID
|
||||||
umount /mnt/restic
|
umount /mnt/restic
|
||||||
|
|||||||
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
original_dir=$(pwd)
|
original_dir=$(pwd)
|
||||||
|
|
||||||
source ./backup-vars.sh
|
source ./vars.sh
|
||||||
cd "$original_dir"
|
cd "$original_dir"
|
||||||
date
|
date
|
||||||
source ./backup-prepare.sh
|
source ./prepare.sh
|
||||||
cd "$original_dir"
|
cd "$original_dir"
|
||||||
date
|
date
|
||||||
source ./backup-send.sh
|
source ./send.sh
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user