backup lotus-land-story
change
commit e1cf99ef7125218956e0f3e7ec70be6526aacdfe
author Alpha Chen <alpha@kejadlen.dev>
date
parent c8f92c1e
diff --git a/dev/homebrew.yml b/dev/homebrew.yml
index 6f9249d..c57766e 100644
--- a/dev/homebrew.yml
+++ b/dev/homebrew.yml
@@ -24,6 +24,7 @@
       - kitty
       - luarocks
       - pam-reattach
+      - restic
       - ripgrep
       - ruby-install
       - shellcheck
diff --git a/lotus-land-story/backup.yml b/lotus-land-story/backup.yml
new file mode 100644
index 0000000..0f82274
--- /dev/null
+++ b/lotus-land-story/backup.yml
@@ -0,0 +1,28 @@
+- name: Backup
+  hosts: lotus-land-story
+  vars_files:
+    - vars.yml
+  # vars:
+  #   version: 2.9.1
+  tasks:
+
+    - name: Install Restic
+      ansible.builtin.package:
+        name: restic
+        state: present
+
+    - name: Update Restic
+      ansible.builtin.command: restic self-update
+
+    - name: Generate SSH key
+      community.crypto.openssh_keypair:
+        path: ~/.ssh/id_ed25519
+        type: ed25519
+
+    - name: Set up daily backup
+      ansible.builtin.template:
+        src: templates/backup.sh
+        dest: /etc/cron.daily/backup
+        mode: '0700'
+
+# vim: ft=yaml.ansible
diff --git a/lotus-land-story/templates/backup.sh b/lotus-land-story/templates/backup.sh
new file mode 100644
index 0000000..a1022ad
--- /dev/null
+++ b/lotus-land-story/templates/backup.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/bash
+
+set -eux pipefail
+
+RESTIC_REPOSITORY=sftp:restic@on-fire-within:/mnt/mushu/restic
+RESTIC_PASSWORD={{ restic.password }}
+
+restic --verbose backup /mnt/lotus-land-story/
+restic --verbose backup --stdin-filename lotus-land-story.sql --stdin-from-command -- sudo -iu postgres pg_dumpall