Files
2025-11-28 20:50:50 -05:00

79 lines
2.3 KiB
YAML

---
- name: Backup block
block:
- name: Create backup root directory
ansible.builtin.file:
path: "{{ gitea_root_backup_dir }}"
state: directory
mode: '0755'
owner: admin
group: admin
- name: Create a directory for this backup
ansible.builtin.file:
path: "{{ gitea_root_backup_dir }}/gitea_backup_{{ ansible_date_time.iso8601_basic }}"
state: directory
mode: '0755'
owner: admin
group: admin
register: gitea_dir_backup_task
- name: Store the backup path as a fact
set_fact:
backup_dir: "{{ gitea_dir_backup_task.path }}"
- name: Create directories for the runner backups
ansible.builtin.file:
path: "{{ backup_dir }}/{{ item.data_mount }}"
state: directory
mode: '0755'
owner: admin
group: admin
loop: "{{ gitea_runners }}"
- name: Stop Gitea service and runners
community.docker.docker_compose_v2:
project_src: "{{ gitea_home_path }}"
state: stopped
- name: Backup Gitea data directory
ansible.builtin.copy:
src: "{{ gitea_home_path }}/data"
dest: "{{ backup_dir }}"
remote_src: yes
mode: preserve
- name: Backup each runner's data directory
ansible.builtin.copy:
src: "{{ gitea_home_path }}/{{ item.data_mount }}"
dest: "{{ backup_dir }}/runners/{{ item.name }}"
remote_src: yes
mode: preserve
loop: "{{ gitea_runners }}"
- name: Start the Gitea service and runners
community.docker.docker_compose_v2:
project_src: "{{ gitea_home_path }}"
state: present
- name: Create a tar.gz archive of the backup
community.general.archive:
path: "{{ backup_dir }}/*"
dest: "{{ backup_dir }}.tar.gz"
format: gz
- name: Copy the backups to the controller
ansible.builtin.fetch:
src: "/{{ backup_dir }}.tar.gz"
dest: "{{ gitea_local_backup_dir }}/{{ backup_dir | basename }}.tar.gz"
flat: yes
rescue:
- name: Start the Gitea service and runners as backup failed
community.docker.docker_compose_v2:
project_src: "{{ gitea_home_path }}"
state: present
- name: Print updating error and cancel
ansible.builtin.fail:
msg: "failed to backup gitea"