--- - name: Install BORG apt: name: - borgbackup become: yes - name: Create BORG repo file: path: '{{ borg_repo_dir }}' state: directory mode: 'u=rwx,g=,o=' become: yes - name: Initialize BORG repo command: cmd: borg init --encryption=repokey creates: '{{ borg_repo_dir }}/config' environment: BORG_REPO: '{{ pgsql_backup.repo_dir }}' BORG_PASSPHRASE: '{{ pgsql_backup.repo_key }}' become: yes - name: Create tempdir file: path: /tmp/postgres state: directory owner: postgres group: postgres mode: 'u=rwx,g=,o=' become: yes - name: Dump databases community.postgresql.postgresql_db: name: '{{ item }}' state: dump target: '/tmp/postgres/{{ item }}.sql' login_unix_socket: '/var/run/postgresql/' loop: '{{ pgsql_dbs }}' become_user: postgres become: yes - name: Create BORG backup command: 'borg create --compression lz4 --verbose ::{hostname}-{now} /tmp/postgres' environment: BORG_REPO: '{{ pgsql_backup.repo_dir }}' BORG_PASSPHRASE: '{{ pgsql_backup.repo_key }}' register: borg_output become: yes - name: Borg Output debug: var: borg_output.stderr - name: Delete TEMP files file: path: /tmp/postgres state: absent become: yes - name: Prune BORG backup command: 'borg prune --list --keep-last 3 --keep-daily 7 --keep-weekly 4 --keep-monthly 6' environment: BORG_REPO: '{{ pgsql_backup.repo_dir }}' BORG_PASSPHRASE: '{{ pgsql_backup.repo_key }}' register: borg_prune become: yes - name: Prune Output debug: var: borg_prune.stderr