reduce backup downtime: restart before rsync transfer

This commit is contained in:
2026-07-27 14:33:04 -04:00
parent 0b70d6e919
commit 400fa84389
4 changed files with 18 additions and 3 deletions
+1
View File
@@ -14,5 +14,6 @@ tags:
- containers - containers
dependencies: dependencies:
"community.docker": ">=1.10.0" "community.docker": ">=1.10.0"
"ansible.posix": ">=1.4.0"
repository: https://git.jaroszew.ski/ansible/ansible-collection-docker-compose-app repository: https://git.jaroszew.ski/ansible/ansible-collection-docker-compose-app
issues: https://git.jaroszew.ski/ansible/ansible-collection-docker-compose-app/issues issues: https://git.jaroszew.ski/ansible/ansible-collection-docker-compose-app/issues
+7
View File
@@ -6,6 +6,11 @@ A flexible Ansible role for deploying and managing Docker Compose applications w
This role provides a standardized way to deploy containerized applications using Docker Compose. It handles directory creation, template rendering, and container lifecycle management. This role provides a standardized way to deploy containerized applications using Docker Compose. It handles directory creation, template rendering, and container lifecycle management.
## Requirements
- Collections: `community.docker` (>=1.10.0) and `ansible.posix` (>=1.4.0). Both are declared as collection dependencies and installed automatically with the collection.
- The backup workflow copies archives to the controller with `ansible.posix.synchronize`, so **`rsync` must be installed on both the controller and the managed host**.
## Features ## Features
- **Template-based deployment** with Jinja2 templating - **Template-based deployment** with Jinja2 templating
@@ -120,6 +125,8 @@ dependencies:
app_backup_stop_services: true # Stop containers during backup app_backup_stop_services: true # Stop containers during backup
``` ```
When `app_backup_stop_services` is enabled the containers are stopped only while the tarball is created on the managed host, then restarted immediately — the transfer of the archive back to the controller (via rsync) happens after the application is running again, so downtime is limited to the snapshot itself.
#### Automated Backups #### Automated Backups
For scheduled backups: For scheduled backups:
+1
View File
@@ -7,3 +7,4 @@ galaxy_info:
collections: collections:
- community.docker - community.docker
- ansible.posix
+9 -3
View File
@@ -51,11 +51,17 @@
mode: "{{ app_permission_mode | default('0644') }}" mode: "{{ app_permission_mode | default('0644') }}"
register: remote_backup register: remote_backup
- name: Restart application after snapshot
community.docker.docker_compose_v2:
project_src: "{{ app_dir }}"
state: present
when: app_backup_stop_services | default(true)
- name: Copy backup to controller - name: Copy backup to controller
ansible.builtin.fetch: ansible.posix.synchronize:
src: "{{ remote_backup.dest }}" src: "{{ remote_backup.dest }}"
dest: "{{ app_backup_path }}/{{ app_name }}-{{ ansible_date_time.iso8601_basic_short }}.tar.gz" dest: "{{ app_backup_path }}/{{ app_name }}-{{ ansible_date_time.iso8601_basic_short }}.tar.gz"
flat: true mode: pull
when: remote_backup is succeeded when: remote_backup is succeeded
- name: Clean old backups on controller - name: Clean old backups on controller
@@ -87,7 +93,7 @@
loop: "{{ old_backups_remote.files | default([]) }}" loop: "{{ old_backups_remote.files | default([]) }}"
always: always:
- name: Restart application after backup - name: Ensure application is running (safety net)
community.docker.docker_compose_v2: community.docker.docker_compose_v2:
project_src: "{{ app_dir }}" project_src: "{{ app_dir }}"
state: present state: present