Fix issues where cryptsetup would fail to unmount

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.
This commit is contained in:
ducoterra
2022-02-01 20:25:26 -05:00
parent 81a0007028
commit 8abfbcf561
5 changed files with 128 additions and 94 deletions

View File

@@ -1,11 +1,15 @@
---
# Backup
- name: Create backup mount directory
- 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
tags: backup
- name: Ensure {{ mount.path }} device exists in crypttab
community.general.crypttab:
name: "{{ disk.name }}"
@@ -15,7 +19,6 @@
state: present
become: yes
no_log: true
tags: backup
- name: Ensure {{ disk.name }} mount exists in fstab
ansible.posix.mount:
path: "{{ mount.path }}"
@@ -24,29 +27,25 @@
opts: nofail,x-systemd.device-timeout=1,noatime,compress=zstd
state: present
become: yes
tags: backup
- name: Ensure /usr/local/scripts exists
file:
state: directory
path: '/usr/local/scripts'
become: yes
tags: backup
- name: Copy btrfs_backup.sh
ansible.builtin.copy:
src: scripts/btrfs_backup.sh
- 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: '0770'
mode: '0744'
become: yes
tags: backup
- 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
tags: backup
loop: "{{ backups }}"
- name: Ensure cronie service started
ansible.builtin.systemd:
@@ -55,4 +54,4 @@
daemon_reload: yes
enabled: yes
become: yes
tags: backup