reduce backup downtime: restart before rsync transfer
This commit is contained in:
@@ -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.
|
||||
|
||||
## 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
|
||||
|
||||
- **Template-based deployment** with Jinja2 templating
|
||||
@@ -120,6 +125,8 @@ dependencies:
|
||||
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
|
||||
|
||||
For scheduled backups:
|
||||
|
||||
@@ -7,3 +7,4 @@ galaxy_info:
|
||||
|
||||
collections:
|
||||
- community.docker
|
||||
- ansible.posix
|
||||
|
||||
@@ -51,11 +51,17 @@
|
||||
mode: "{{ app_permission_mode | default('0644') }}"
|
||||
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
|
||||
ansible.builtin.fetch:
|
||||
ansible.posix.synchronize:
|
||||
src: "{{ remote_backup.dest }}"
|
||||
dest: "{{ app_backup_path }}/{{ app_name }}-{{ ansible_date_time.iso8601_basic_short }}.tar.gz"
|
||||
flat: true
|
||||
mode: pull
|
||||
when: remote_backup is succeeded
|
||||
|
||||
- name: Clean old backups on controller
|
||||
@@ -87,7 +93,7 @@
|
||||
loop: "{{ old_backups_remote.files | default([]) }}"
|
||||
|
||||
always:
|
||||
- name: Restart application after backup
|
||||
- name: Ensure application is running (safety net)
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: "{{ app_dir }}"
|
||||
state: present
|
||||
|
||||
Reference in New Issue
Block a user