From a123f8f7cf82f289c60f964bec09d2e76512180a Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Sun, 3 Dec 2023 14:26:52 +0100 Subject: [PATCH] Store backup.yaml and sources.yaml in different repositories. --- backup.service | 8 ++++++-- backup.yaml | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 backup.yaml diff --git a/backup.service b/backup.service index 7243a16..a313b31 100644 --- a/backup.service +++ b/backup.service @@ -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 index 0000000..ae809b9 --- /dev/null +++ b/backup.yaml @@ -0,0 +1,27 @@ +# Copyright (c) 2023 Jakub Czajka +# 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 }}" -- 2.39.5