summaryrefslogtreecommitdiff
path: root/ansible/roles/holywood2
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-07-09 09:57:29 +0300
committerLars Wirzenius <liw@liw.fi>2018-07-09 09:57:29 +0300
commitc7912e21bbf298d6d8095ef802aab4482c97bf07 (patch)
tree1fa684b93edfa78d71ad27fbb1fd16cb2cfa586a /ansible/roles/holywood2
parent3971955a5e132e67d5476085eb7a32d45fece8bb (diff)
downloadansibleness-c7912e21bbf298d6d8095ef802aab4482c97bf07.tar.gz
Change: smarthost-client role, backups for holywood2
Diffstat (limited to 'ansible/roles/holywood2')
-rwxr-xr-xansible/roles/holywood2/files/borg-all17
-rwxr-xr-xansible/roles/holywood2/files/run-borg22
-rw-r--r--ansible/roles/holywood2/tasks/main.yml24
3 files changed, 63 insertions, 0 deletions
diff --git a/ansible/roles/holywood2/files/borg-all b/ansible/roles/holywood2/files/borg-all
new file mode 100755
index 0000000..bbc982a
--- /dev/null
+++ b/ansible/roles/holywood2/files/borg-all
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+ts="$(date +%Y-%m-%dT%H:%M:%S)"
+
+echo "Backing up /mnt/soile"
+./run-borg willikins /mnt/backups/borg create -p --stats ::"soile-$ts)" /mnt/soile/
+
+echo "Backing up /mnt/media"
+./run-borg willikins /mnt/backups/borg create -p --stats ::"media-$ts)" /mnt/media/
+
+echo "Backing up /mnt/liw-backups"
+./run-borg willikins /mnt/backups/borg create -p --stats ::"liw-$ts)" /mnt/liw-backups/
+
+echo "Pruning"
+./run-borg willikins /mnt/backups/borg prune --keep-with 100d
+
+echo "Backup finished"
diff --git a/ansible/roles/holywood2/files/run-borg b/ansible/roles/holywood2/files/run-borg
new file mode 100755
index 0000000..7225a94
--- /dev/null
+++ b/ansible/roles/holywood2/files/run-borg
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+set -eu
+
+hostname="$(hostname)"
+target="$1"
+export targetdir="$2"
+shift 2
+
+export BORG_REPO="$target:$targetdir"
+export BORG_PASSCOMMAND="cat /etc/borg-passphrase"
+
+if borg init --encryption=repokey
+then
+ borg upgrade --disable-tam
+fi
+
+DATE="$(date +%Y-%m-%dT%H%M%S)"
+
+echo borg "$@"
+borg "$@"
+echo borg finished
diff --git a/ansible/roles/holywood2/tasks/main.yml b/ansible/roles/holywood2/tasks/main.yml
index fbd5224..a6a7171 100644
--- a/ansible/roles/holywood2/tasks/main.yml
+++ b/ansible/roles/holywood2/tasks/main.yml
@@ -22,3 +22,27 @@
owner: root
group: root
mode: 0644
+
+- name: install borg
+ apt:
+ name: borgbackup
+ default_release: stretch-backports
+
+- name: install borg scripting
+ copy:
+ src: "{{ item }}"
+ dest: /root
+ owner: root
+ group: root
+ mode: 0755
+ with_items:
+ - run-borg
+ - borg-all
+
+- name: install borg passphrase
+ copy:
+ content: "{{ lookup('pipe', 'pass borg/holywood2-to-willikins') }}"
+ dest: /etc/borg-passphrase
+ owner: root
+ group: root
+ mode: 0600