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

87 lines
2.4 KiB
YAML

---
- name: Select backup file on localhost
delegate_to: localhost
become: no
block:
- name: Find all backup files in the directory
find:
paths: "{{ gitea_local_backup_dir }}"
patterns: "gitea_backup_*.tar.gz"
file_type: file
register: backup_files
- name: Print files
debug:
msg: "files found {{ backup_files }}"
- name: Set gitea_backup_file if not defined or empty
when: gitea_backup_file is not defined or gitea_backup_file == ""
block:
- name: Sort backup files by timestamp in filename and select newest
set_fact:
gitea_backup_file: "{{ backup_files.files | sort(attribute='path') | last | default({}) | json_query('path') }}"
when: backup_files.files | length > 0
- name: Fail if no backup files found
fail:
msg: "No backup files found in {{ gitea_local_backup_dir }}"
when: backup_files.files | length == 0
- name: Display selected backup file
debug:
msg: "Using backup file: {{ gitea_backup_file }}"
- name: Verify backup file exists
stat:
path: "{{ gitea_backup_file }}"
register: final_backup_check
- name: Fail if backup file doesn't exist
fail:
msg: "Backup file does not exist: {{ gitea_backup_file }}"
when: not final_backup_check.stat.exists
- name: Stop Gitea service and runners
community.docker.docker_compose_v2:
project_src: /opt/gitea
state: stopped
- name: Remove existing data directory
file:
path: "{{ gitea_home_path }}/data"
state: absent
- name: Remove existing runner directories
file:
path: "{{ gitea_home_path }}/{{ item.data_mount }}"
state: absent
loop: "{{ gitea_runners }}"
- name: Copy backup file to remote host
copy:
src: "{{ gitea_backup_file }}"
dest: "{{ gitea_home_path }}/{{ gitea_backup_file | basename }}"
mode: preserve
register: copy_result
- name:
- name: Extract backup archive on remote host
unarchive:
src: "{{ gitea_home_path }}/{{ gitea_backup_file | basename }}"
dest: "{{ gitea_home_path }}"
remote_src: yes
register: extract_result
- name: Fix ownership of extracted files
file:
path: "{{ gitea_home_path }}"
owner: admin
group: admin
recurse: yes
- name: Delete backup archive from remote host
file:
path: "{{ gitea_home_path }}/{{ gitea_backup_file | basename }}"
state: absent