aboutsummaryrefslogtreecommitdiff
path: root/ansible
diff options
context:
space:
mode:
Diffstat (limited to 'ansible')
-rw-r--r--ansible/roles/borg-client/tasks/main.yml37
-rw-r--r--ansible/roles/borg-client/templates/bin/create-backup2
-rw-r--r--ansible/roles/borg-client/templates/bin/create-backup-send-email17
3 files changed, 51 insertions, 5 deletions
diff --git a/ansible/roles/borg-client/tasks/main.yml b/ansible/roles/borg-client/tasks/main.yml
index a65ae3e..8925d84 100644
--- a/ansible/roles/borg-client/tasks/main.yml
+++ b/ansible/roles/borg-client/tasks/main.yml
@@ -33,6 +33,7 @@
become: yes
copy:
dest: /etc/borg/env
+ mode: u=r,go=
content: |
BORG_REPO="borg@{{ borg_client__server }}:{{ ansible_hostname }}"
BORG_RSH="ssh -i {{ ssh_key}}"
@@ -70,11 +71,14 @@
- name: /usr/local/bin/create-backup
become: yes
template:
- dest: /usr/local/bin/create-backup
- src: bin/create-backup
- mode: u=rx,go=
+ dest: "/usr/local/bin/{{ item }}"
+ src: "bin/{{ item }}"
+ mode: u=rwx,go=rx
owner: root
group: root
+ with_items:
+ - create-backup
+ - create-backup-send-email
- become: yes
copy:
@@ -86,10 +90,35 @@
[Service]
Type=oneshot
WorkingDirectory=/
- ExecStart=/usr/local/bin/create-backup
+ ExecStart=-/usr/local/bin/create-backup
+ ExecStartPost=-/usr/local/bin/create-backup-send-email root@trygvis.io
+ SuccessExitStatus=0 1
+
+# OnFailure=create-backup-send-email.service
+# OnSuccess=create-backup-send-email.service
register: create_backup_service
- when: create_backup_service.changed
become: yes
systemd:
daemon_reload: yes
+
+- become: yes
+ copy:
+ dest: /etc/systemd/system/create-backup-send-email.service
+ content: |
+ [Unit]
+ Description=Send email after creating backup
+
+ [Service]
+ Type=oneshot
+ WorkingDirectory=/
+ ExecStart=/usr/local/bin/create-backup-send-email root@trygvis.io
+ User=nobody
+ Group=systemd-journal
+ register: create_backup_send_email_service
+
+- when: create_backup_send_email_service.changed
+ become: yes
+ systemd:
+ daemon_reload: yes
diff --git a/ansible/roles/borg-client/templates/bin/create-backup b/ansible/roles/borg-client/templates/bin/create-backup
index dfbe72d..cf75edf 100644
--- a/ansible/roles/borg-client/templates/bin/create-backup
+++ b/ansible/roles/borg-client/templates/bin/create-backup
@@ -11,7 +11,7 @@ export BORG_RSH
cmd=()
cmd+=(borg create)
cmd+=(--stats)
-cmd+=(--progress)
+#cmd+=(--progress)
cmd+=(--json)
cmd+=(--exclude-from=/etc/borg/excludes)
cmd+=(--patterns-from=/etc/borg/patterns)
diff --git a/ansible/roles/borg-client/templates/bin/create-backup-send-email b/ansible/roles/borg-client/templates/bin/create-backup-send-email
new file mode 100644
index 0000000..65286b1
--- /dev/null
+++ b/ansible/roles/borg-client/templates/bin/create-backup-send-email
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -euo pipefail
+
+cd /
+
+
+/usr/sbin/sendmail -t <<ERRMAIL
+To: $1
+From: systemd <root@$HOSTNAME>
+Subject: Backup @ $HOSTNAME
+Content-Transfer-Encoding: 8bit
+Content-Type: text/plain; charset=UTF-8
+
+$(systemctl status --full 2>&1)
+$(journalctl --since today --unit create-backup 2>&1)
+ERRMAIL