From e5b94acb46c270f34cfa1c86138b6e52dcfeb14a Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 15 Nov 2021 18:20:21 +0100 Subject: [PATCH] add the backup script programmitcally --- tasks/main.yml | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 6a3a264..dd3387c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -24,13 +24,35 @@ when: restic_extract is changed - name: "Copy the backup script" - template: - src: "backup-to-restic.j2" - dest: "/home/ansible/backup-to-restic" - directory_mode: yes + blockinfile: + path: "/home/ansible/backup-to-restic" + mode: 0755 owner: "ansible" group: "ansible" + block: | + #!/bin/bash + export RESTIC_REPOSITORY=sftp:borg@10.7.89.117:restic + export RESTIC_PASSWORD={{ restic_password }} + + cd {{ docker_project_path }} + sudo docker-compose pause + sudo -E restic backup /home/ansible --exclude-file=/etc/restic/excludes.txt + sudo docker-compose unpause + when: "'docker' in group_names" + +- name: "Copy the backup script" + blockinfile: + path: "/home/andreas/backup-to-restic" mode: 0755 + owner: "andreas" + group: "andreas" + block: | + #!/bin/bash + export RESTIC_REPOSITORY=sftp:borg@10.7.89.117:restic + export RESTIC_PASSWORD={{ restic_password }} + + restic backup /home/andreas --exclude-file=/etc/restic/excludes.txt + when: "'docker' not in group_names" - name: "Create the restic config dir" file: