homelab/roles/rsnapshot/tasks/main.yml

72 lines
2.4 KiB
YAML
Raw Normal View History

# Copyright (C) 2021 Kris Lamoureux
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
- name: Install rsnapshot
2023-05-04 03:27:03 +00:00
ansible.builtin.apt:
name: rsnapshot
state: present
- name: Create rsnapshot system directories
2023-05-04 03:27:03 +00:00
ansible.builtin.file:
path: "{{ item }}"
state: directory
loop:
- "{{ rsnapshot_confdir }}"
- "{{ rsnapshot_logdir }}"
- name: Create snapshot_root directories
2023-05-04 03:27:03 +00:00
ansible.builtin.file:
path: "{{ item.root | default(rsnapshot_root) }}"
state: directory
loop: "{{ rsnapshot }}"
- name: Install rsnapshot configuration
2023-05-04 03:27:03 +00:00
ansible.builtin.template:
src: rsnapshot.conf.j2
dest: "{{ rsnapshot_confdir }}/{{ item.name }}.conf"
loop: "{{ rsnapshot }}"
- name: Install rsnapshot crons
2023-05-04 03:27:03 +00:00
ansible.builtin.cron:
name: "{{ item.1.interval }} rsnapshot of {{ item.0.name }}"
2021-06-08 04:33:55 +00:00
job: "/usr/bin/rsnapshot -c {{ rsnapshot_confdir }}/{{ item.0.name }}.conf {{ item.1.interval }} >/dev/null"
user: "root"
minute: "{{ item.1.minute | default('*') }}"
hour: "{{ item.1.hour | default('*') }}"
day: "{{ item.1.day | default('*') }}"
weekday: "{{ item.1.weekday | default('*') }}"
month: "{{ item.1.month | default('*') }}"
cron_file: "rsnapshot-{{ item.0.name }}"
with_subelements:
- "{{ rsnapshot }}"
- cron
2021-06-08 04:33:55 +00:00
- name: Install rsnapshot report script
2023-05-04 03:27:03 +00:00
ansible.builtin.template:
2021-06-08 04:33:55 +00:00
src: rsnapshot-report.sh.j2
dest: /usr/local/bin/rsnapshot-report
mode: '0750'
- name: Install rsnapshot report crons
2023-05-04 03:27:03 +00:00
ansible.builtin.cron:
2021-06-08 04:33:55 +00:00
name: "{{ item.name }} rsnapshot report email"
job: "/usr/local/bin/rsnapshot-report {{ rsnapshot_reportlog }}
| mail -s '{{ item.report.subject | default('Backup Report') }}' {{ item.report.to }}"
user: "root"
minute: '0'
hour: '0'
cron_file: "rsnapshot-{{ item.name }}"
loop: "{{ rsnapshot }}"
when: item.report is defined