3
0
forked from jakub/ansible

edit init 1

This commit is contained in:
fencl
2025-10-03 13:36:35 +02:00
parent b247ea0832
commit 2b5a2b4a1a
6 changed files with 288 additions and 0 deletions

38
nextcloud_backup.yml Normal file
View File

@@ -0,0 +1,38 @@
---
- 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