Added lnd channel backup to s3 role.
authorLuke Hoersten <luke@hoersten.org>
Mon, 05 Jul 2021 10:46:30 -0500
changeset 19 5c8335b57353
parent 18 12e90527dfdc
child 20 4f4893542c40
Added lnd channel backup to s3 role.
lnd-channel-s3-backup/files/lnd-channel-s3-backup.sh
lnd-channel-s3-backup/handlers/main.yaml
lnd-channel-s3-backup/meta/main.yaml
lnd-channel-s3-backup/tasks/main.yaml
lnd-channel-s3-backup/templates/[email protected]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lnd-channel-s3-backup/files/lnd-channel-s3-backup.sh	Mon Jul 05 10:46:30 2021 -0500
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+BUCKET=$1
+CHAN_BACKUP=$2
+
+aws s3 mb "s3://$BUCKET/"
+aws s3api put-bucket-versioning --bucket "$BUCKET" --versioning-configuration Status=Enabled
+
+while true; do
+    inotifywait $CHAN_BACKUP
+    aws s3 cp $CHAN_BACKUP "s3://$BUCKET/"
+done
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lnd-channel-s3-backup/handlers/main.yaml	Mon Jul 05 10:46:30 2021 -0500
@@ -0,0 +1,5 @@
+---
+
+- name: reload s3 backup service
+  systemd: name="lnd-channel-s3-backup@{{lnd_channel_s3_backup_bucket}}.service" enabled="yes" daemon_reload="yes"
+  become: yes
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lnd-channel-s3-backup/meta/main.yaml	Mon Jul 05 10:46:30 2021 -0500
@@ -0,0 +1,4 @@
+---
+
+dependencies:
+  - aws-s3-backup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lnd-channel-s3-backup/tasks/main.yaml	Mon Jul 05 10:46:30 2021 -0500
@@ -0,0 +1,25 @@
+---
+
+# https://gist.github.com/alexbosworth/2c5e185aedbdac45a03655b709e255a3
+
+- name: install lnd-channel s3 backup apt packages
+  become: yes
+  apt: name="inotify-tools"
+
+- name: create lnd-channel s3 backup shell script
+  become: yes
+  copy:
+    src: "lnd-channel-s3-backup.sh"
+    dest: "/usr/local/bin/lnd-channel-s3-backup.sh"
+    mode: "0755"
+
+- name: configure lnd-channel s3 backup systemd service
+  become: yes
+  template:
+    src: "[email protected]"
+    dest: "/lib/systemd/system/lnd-channel-s3-backup@{{lnd_channel_s3_backup_bucket}}.service"
+  notify: reload s3 backup service
+
+- name: ensure lnd-channel s3 backup service is started
+  become: yes
+  systemd: name="lnd-channel-s3-backup@{{lnd_channel_s3_backup_bucket}}.service" enabled="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lnd-channel-s3-backup/templates/[email protected]	Mon Jul 05 10:46:30 2021 -0500
@@ -0,0 +1,10 @@
+[Unit]
+Description=LND channel s3 backup for "%I"
+
+[Service]
+ExecStart=/usr/local/bin/lnd-channel-s3-backup.sh %i "{{lnd_channel_s3_backup}}"
+Restart=always
+RestartSec=1
+
+[Install]
+WantedBy=multi-user.target