homelab/roles/rsnapshot/tasks/main.yml

72 lines
2.3 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
apt:
name: rsnapshot
state: present
- name: Create rsnapshot system directories
file:
path: "{{ item }}"
state: directory
loop:
- "{{ rsnapshot_confdir }}"
- "{{ rsnapshot_logdir }}"
- name: Create snapshot_root directories
file:
path: "{{ item.root | default(rsnapshot_root) }}"
state: directory
loop: "{{ rsnapshot }}"
- name: Install rsnapshot configuration
template:
src: rsnapshot.conf.j2
dest: "{{ rsnapshot_confdir }}/{{ item.name }}.conf"
loop: "{{ rsnapshot }}"
- name: Install rsnapshot crons
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
template:
src: rsnapshot-report.sh.j2
dest: /usr/local/bin/rsnapshot-report
mode: '0750'
- name: Install rsnapshot report crons
cron:
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