]> git.ekhem.eu.org Git - cron.git/commitdiff
Store backup.yaml and sources.yaml in different repositories.
authorJakub Czajka <jakub@ekhem.eu.org>
Sun, 3 Dec 2023 13:26:52 +0000 (14:26 +0100)
committerJakub Czajka <jczajka@google.com>
Sun, 24 Dec 2023 18:34:02 +0000 (19:34 +0100)
backup.service
backup.yaml [new file with mode: 0644]

index 7243a16ee8a9ddfce61b1db399ca17de0faf2cc4..a313b31f405cf860105c9ff893b0bdf8f177c4ac 100644 (file)
@@ -10,8 +10,12 @@ Type=oneshot
 EnvironmentFile=/etc/ansible/facts.d/env.fact
 ExecStartPre=/usr/bin/git \
     --work-tree=/tmp \
-    --git-dir=${git_home_dir}/turnup.git \
-    checkout main --force sources.yaml backup.yaml
+    --git-dir=${git_home_dir}/config.git \
+    checkout main --force sources.yaml
+ExecStartPre=/usr/bin/git \
+    --work-tree=/tmp \
+    --git-dir=${git_home_dir}/cron.git \
+    checkout main --force backup.yaml
 ExecStart=/usr/bin/ansible-playbook /tmp/backup.yaml \
     --connection=local \
     --extra-vars token=${gdrive_auth_token} \
diff --git a/backup.yaml b/backup.yaml
new file mode 100644 (file)
index 0000000..ae809b9
--- /dev/null
@@ -0,0 +1,27 @@
+# Copyright (c) 2023 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+- hosts: servers
+  vars:
+    auth_token: "{{ lookup('file', '{{ token }}') | to_nice_json }}"
+    encryption_key: "{{ lookup('file', '{{ key }}') }}"
+  tasks:
+    - set_fact:
+        inputs: "{{ lookup('file', '{{ sources }}') | from_yaml }}"
+    - name: Install gdrive_knife
+      pip:
+        name: gdrive_knife
+        extra_args: --break-system-packages
+        state: latest
+      become: true
+    - name: Clear /tmp
+      shell: rm --recursive --force /tmp/*
+      become: true
+    - name: Dump database to /tmp/database
+      command: pg_dumpall --user=postgres --clean --file=/tmp/database
+    - name: Upload file
+      command: python3 -m gdrive_knife upload --token {{ auth_token }} \
+        --key {{ encryption_key }} {{ item.dest }}/{{ item.name }} \
+        {{ item.name }}
+      become: true
+      with_items: "{{ inputs }}"