3
0
forked from jakub/ansible
Files
ansible_fencl/nextcloud/nextcloud_backup.yml
fencl 65ea83638d Add Nextcloud deployment and management playbooks
- Introduced playbooks for health checks, Collabora updates, Nextcloud backups, upgrades, and Redis updates.
- Each playbook includes necessary tasks for managing services in a Docker environment.
2025-10-03 14:04:31 +02:00

38 lines
1.3 KiB
YAML

---
- 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