There were occasions where removing the backup drive would confuse luks and prevent re-mounting. This fixes the issue by attempting to luks close and open the drive before mounting, thereby correcting any issues where the drive would stick.
58 lines
1.4 KiB
YAML
58 lines
1.4 KiB
YAML
---
|
|
# Backup
|
|
- name: Ensure snapshot directory
|
|
file:
|
|
state: directory
|
|
path: "{{ snapshots.path }}"
|
|
become: yes
|
|
- name: Ensure backup mount directory
|
|
file:
|
|
state: directory
|
|
path: "{{ mount.path }}"
|
|
become: yes
|
|
- name: Ensure {{ mount.path }} device exists in crypttab
|
|
community.general.crypttab:
|
|
name: "{{ disk.name }}"
|
|
backing_device: "UUID={{ disk.uuid }}"
|
|
password: "{{ disk.password }}"
|
|
opts: luks
|
|
state: present
|
|
become: yes
|
|
no_log: true
|
|
- name: Ensure {{ disk.name }} mount exists in fstab
|
|
ansible.posix.mount:
|
|
path: "{{ mount.path }}"
|
|
src: /dev/mapper/{{ disk.name }}
|
|
fstype: btrfs
|
|
opts: nofail,x-systemd.device-timeout=1,noatime,compress=zstd
|
|
state: present
|
|
become: yes
|
|
- name: Ensure /usr/local/scripts exists
|
|
file:
|
|
state: directory
|
|
path: '/usr/local/scripts'
|
|
become: yes
|
|
- name: Template btrfs_backup.sh
|
|
ansible.builtin.template:
|
|
src: btrfs_backup.sh.j2
|
|
dest: /usr/local/scripts/btrfs_backup.sh
|
|
owner: root
|
|
group: root
|
|
mode: '0744'
|
|
become: yes
|
|
- name: Ensure hourly backups of each item in backups
|
|
ansible.builtin.cron:
|
|
name: "hourly backup of {{ item }}"
|
|
minute: "0"
|
|
job: "export SOURCE_DIR={{ item }}; /usr/local/scripts/btrfs_backup.sh"
|
|
become: yes
|
|
loop: "{{ backups }}"
|
|
- name: Ensure cronie service started
|
|
ansible.builtin.systemd:
|
|
name: cronie
|
|
state: restarted
|
|
daemon_reload: yes
|
|
enabled: yes
|
|
become: yes
|
|
|