Skip to content

Commit d080dbd

Browse files
committed
* add archive role that replaces rsync job for /config folder
1 parent 26baa79 commit d080dbd

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed

ansible/playbook_main.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,32 @@
7878
- "/share/web/fileshare/"
7979
- "/share/web/gallery/"
8080

81+
- role: archive
82+
vars:
83+
archive_jobs:
84+
- name: "backup-config-{{ hostname_main }}"
85+
user: "root"
86+
dest: "/share/backups/{{ hostname_main }}/config/"
87+
timer_OnCalendar: "*-*-* 04:30:00"
88+
steps:
89+
- { name: "actual", src: "/config/actual" }
90+
- { name: "adguard", src: "/config/adguard" }
91+
- { name: "bitwarden", src: "/config/bitwarden" }
92+
- { name: "homeassistant", src: "/config/homeassistant", opts: '--exclude="home-assistant_v2.db*"' }
93+
- { name: "jdownloader", src: "/config/jdownloader" }
94+
- { name: "jellyfin", src: "/config/jellyfin", opts: '--exclude="cache" --exclude="data/metadata" --exclude="data/transcodes"' }
95+
- { name: "jellyseerr", src: "/config/jellyseerr" }
96+
- { name: "lyrion", src: "/config/lyrion", opts: '--exclude="config/cache"' }
97+
- { name: "mumble", src: "/config/mumble" }
98+
- { name: "transmission", src: "/config/transmission" }
99+
81100
- role: rsync
82101
vars:
83102
rsync_jobs:
84103
- name: "backups-{{ hostname_main }}"
85104
user: "root"
86105
timer_OnCalendar: "*-*-* *:20:00"
87106
steps:
88-
- { src: "/config", dest: "/share/backups/{{ hostname_main }}/config", opts: '--exclude="home-assistant_v2.db*" --exclude="jellyfin" --exclude="lyrion/config/cache"' }
89107
- { src: "/git", dest: "/share/backups/{{ hostname_main }}/git" }
90108
- { src: "/share-common", dest: "/share/backups/{{ hostname_main }}/share-common", opts: '--exclude="downloads"' }
91109

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
archive_script_folder: "/opt/archive_scripts"
4+
archive_jobs: []

ansible/roles/archive/tasks/job.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
3+
- ansible.builtin.set_fact:
4+
script: "{{ archive_script_folder }}/{{ archive_job.name }}.bash"
5+
6+
- ansible.builtin.include_role:
7+
name: systemd-timer
8+
vars:
9+
sd_timer_name: "{{ archive_job.name }}"
10+
sd_timer_command: "{{ script }}"
11+
sd_timer_OnCalendar: "{{ archive_job.timer_OnCalendar | default('*-*-* 02:00:00') }}"
12+
sd_timer_user: "{{ archive_job.user | default(ansible_env.USER) }}"
13+
sd_timer_persistent: true
14+
15+
- name: "Create job script: '{{ script }}'"
16+
become: true
17+
ansible.builtin.template:
18+
src: "job_script.j2"
19+
dest: "{{ script }}"
20+
mode: "755"
21+
22+
- name: "Create jobs source folders"
23+
become: true
24+
ansible.builtin.file:
25+
path: "{{ item.src }}"
26+
state: directory
27+
mode: "ug+rw"
28+
owner: "{{ archive_job.user }}"
29+
group: 'users'
30+
with_items: "{{ archive_job.steps }}"
31+
32+
- name: "Create jobs destination folder"
33+
become: true
34+
ansible.builtin.file:
35+
path: "{{ archive_job.dest }}"
36+
state: directory
37+
mode: "ug+rw"
38+
owner: "{{ archive_job.user }}"
39+
group: 'users'

ansible/roles/archive/tasks/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
3+
- name: "Create scripts folder: '{{ archive_script_folder }}'"
4+
become: true
5+
ansible.builtin.file:
6+
path: "{{ archive_script_folder }}"
7+
state: directory
8+
mode: "u+rw"
9+
recurse: true
10+
11+
- ansible.builtin.include_tasks: tasks/job.yml
12+
with_items: "{{ archive_jobs }}"
13+
loop_control:
14+
loop_var: archive_job
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
{% if archive_job.pre_sleep_seconds is defined %}
4+
5+
echo "pre-sleep: {{ archive_job.pre_sleep_seconds }} seconds"
6+
sleep {{ archive_job.pre_sleep_seconds }}
7+
printf "************************************************************************************\n\n"
8+
9+
{% endif %}
10+
11+
12+
{% for step in archive_job.steps %}
13+
14+
FILE="{{ archive_job.dest }}/{{ step.name }}.tar.gz"
15+
16+
echo "run archive step: {{ step.src }} into '${FILE}'"
17+
tar -zcvf "${FILE}" {{ step.opts | default('') }} "{{ step.src }}"
18+
19+
echo "make accessible for 'users' group '${FILE}'"
20+
chmod 644 "${FILE}"
21+
chown {{ archive_job.user }}:users "${FILE}"
22+
23+
printf "************************************************************************************\n\n"
24+
25+
{% endfor %}
26+
27+
28+
{% if archive_job.post_command is defined %}
29+
30+
echo "post-command: {{ archive_job.post_command }}"
31+
{{ archive_job.post_command }}
32+
printf "************************************************************************************\n\n"
33+
34+
{% endif %}

0 commit comments

Comments
 (0)