--- - name: Nextcloud backup (config, custom_apps, DB) hosts: proxmox become: true vars: nc_root: /data/compose/nextcloud backup_dir: "{{ nc_root }}/backup-{{ ansible_date_time.date }}" db_container: nextcloud-db tasks: - name: Ensure backup directory exists ansible.builtin.file: path: "{{ backup_dir }}" state: directory mode: '0755' # Use archive module to create tar.gz directly on the remote host - name: Archive config directory ansible.builtin.archive: path: "{{ nc_root }}/config" dest: "{{ backup_dir }}/config.tgz" format: gz - name: Archive custom_apps directory ansible.builtin.archive: path: "{{ nc_root }}/custom_apps" dest: "{{ backup_dir }}/custom_apps.tgz" format: gz # Dump DB directly to a file on the host (avoid shuttling dump through Ansible) - name: Dump MariaDB from container to file ansible.builtin.shell: | set -euo pipefail docker exec {{ db_container }} sh -c 'command -v mariadb-dump >/dev/null && mariadb-dump -u"$$MYSQL_USER" -p"$$MYSQL_PASSWORD" "$$MYSQL_DATABASE" || mysqldump -u"$$MYSQL_USER" -p"$$MYSQL_PASSWORD" "$$MYSQL_DATABASE"' \ > "{{ backup_dir }}/db.sql" args: executable: /bin/bash