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: