mirror of
https://github.com/Crocmagnon/ansible.git
synced 2024-11-21 14:58:02 +01:00
Compare commits
2 commits
d94c594d4b
...
d2417fc187
Author | SHA1 | Date | |
---|---|---|---|
d2417fc187 | |||
fbdfcaac4d |
4 changed files with 66 additions and 3 deletions
57
playbooks/apps/files/bin/borg-sync
Executable file
57
playbooks/apps/files/bin/borg-sync
Executable file
|
@ -0,0 +1,57 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Change all the variables below to suit your needs:
|
||||
SOURCE_DIRECTORY="/mnt/data/nextcloud-aio/backups/borg"
|
||||
RCLONE_CONFIG="borgbase-nextcloud-aio"
|
||||
|
||||
TARGET_DIRECTORY="repo" # this is the BorgBase directory name: modify it only if you want to specify a different one (discouraged)
|
||||
|
||||
########################################
|
||||
# DO NOT modify any of the following! #
|
||||
########################################
|
||||
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "run as root"
|
||||
output 1
|
||||
fi
|
||||
|
||||
if ! [ -d "$SOURCE_DIRECTORY" ]; then
|
||||
echo "The root directory does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$(ls -A "$SOURCE_DIRECTORY/")" ]; then
|
||||
echo "The source directory is empty, which is not allowed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$SOURCE_DIRECTORY/lock.roster" ]; then
|
||||
echo "Unable to execute the script as the backup archive is currently modified. Please try again later."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f "$SOURCE_DIRECTORY/aio-lockfile" ]; then
|
||||
echo "Cannot continue because aio-lockfile already exists."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
touch "$SOURCE_DIRECTORY/aio-lockfile"
|
||||
|
||||
|
||||
if ! rclone sync -v --exclude aio-lockfile "$SOURCE_DIRECTORY/" "$RCLONE_CONFIG:$TARGET_DIRECTORY"; then
|
||||
if docker ps --format "{{.Names}}" | grep "^nextcloud-aio-nextcloud$"; then
|
||||
docker exec -en nextcloud-aio-nextcloud bash /notify.sh "Rclone failed." "Failed to synchronise the backup repository with the target directory."
|
||||
else
|
||||
echo "Failed to synchronise the backup repository with the target directory."
|
||||
fi
|
||||
rm "$SOURCE_DIRECTORY/aio-lockfile"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm "$SOURCE_DIRECTORY/aio-lockfile"
|
||||
|
||||
if docker ps --format "{{.Names}}" | grep "^nextcloud-aio-nextcloud$"; then
|
||||
docker exec -en nextcloud-aio-nextcloud bash /notify.sh "Rclone backup successful!" "Synchronised the backup repository successfully."
|
||||
else
|
||||
echo "Synchronised the backup repository successfully."
|
||||
fi
|
|
@ -12,7 +12,7 @@
|
|||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ dir }}/"
|
||||
mode: "0600"
|
||||
mode: preserve
|
||||
with_fileglob:
|
||||
- files/{{ app_name }}/*
|
||||
- files/{{ app_name }}/.*
|
||||
|
|
|
@ -15,6 +15,12 @@
|
|||
minute: 30
|
||||
hour: "*/3"
|
||||
job: /mnt/data/bin/healthcheck restic-prune /mnt/data/bin/restic-prune
|
||||
- name: Cron - Borgbase sync
|
||||
ansible.builtin.cron:
|
||||
name: borgbase sync
|
||||
minute: 30
|
||||
hour: 3
|
||||
job: /mnt/data/bin/healthcheck borg-sync /mnt/data/bin/borg-sync
|
||||
- name: Cron - SMART short
|
||||
ansible.builtin.cron:
|
||||
name: SMART short
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ docker_dir }}/"
|
||||
mode: "0600"
|
||||
mode: preserve
|
||||
with_fileglob:
|
||||
- files/{{ docker_app_name }}/*
|
||||
- files/{{ docker_app_name }}/.*
|
||||
|
@ -18,7 +18,7 @@
|
|||
ansible.builtin.template:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ docker_dir }}/{{ item | basename | regex_replace('\\.j2$', '') }}"
|
||||
mode: "0600"
|
||||
mode: preserve
|
||||
with_fileglob:
|
||||
- templates/{{ docker_app_name }}/*.j2
|
||||
- templates/{{ docker_app_name }}/.*.j2
|
||||
|
|
Loading…
Reference in a new issue