102 lines
2.6 KiB
YAML
102 lines
2.6 KiB
YAML
---
|
|
- name: Create backup directory on ops server
|
|
file:
|
|
path: "{{ backup_dest_dir }}"
|
|
state: directory
|
|
mode: '0755'
|
|
owner: asxpi
|
|
group: asxpi
|
|
delegate_to: asxpio-ops
|
|
become: true
|
|
|
|
- name: Find existing Forgejo dump files on old server
|
|
find:
|
|
paths: /srv/gitea
|
|
patterns: "*.zip"
|
|
file_type: file
|
|
register: existing_dumps
|
|
|
|
- name: Create temporary staging directory for backup
|
|
file:
|
|
path: /tmp/forgejo-backup-staging
|
|
state: directory
|
|
mode: '0755'
|
|
become: true
|
|
|
|
- name: Copy database to staging
|
|
copy:
|
|
src: /srv/gitea/gitea.db
|
|
dest: /tmp/forgejo-backup-staging/gitea.db
|
|
remote_src: true
|
|
become: true
|
|
|
|
- name: Create data directory in staging
|
|
file:
|
|
path: /tmp/forgejo-backup-staging/data
|
|
state: directory
|
|
mode: '0755'
|
|
become: true
|
|
|
|
- name: Copy data directories to staging
|
|
copy:
|
|
src: "/srv/gitea/data/{{ item }}/"
|
|
dest: "/tmp/forgejo-backup-staging/data/{{ item }}/"
|
|
remote_src: true
|
|
loop:
|
|
- avatars
|
|
- repo-avatars
|
|
- repo-archive
|
|
- attachments
|
|
- gitea-repositories
|
|
become: true
|
|
ignore_errors: true
|
|
|
|
- name: Create backup archive from staging
|
|
archive:
|
|
path: /tmp/forgejo-backup-staging
|
|
dest: /tmp/forgejo-full-backup-{{ ansible_date_time.date }}.tar.gz
|
|
format: gz
|
|
become: true
|
|
|
|
- name: Clean up staging directory
|
|
file:
|
|
path: /tmp/forgejo-backup-staging
|
|
state: absent
|
|
become: true
|
|
|
|
- name: Display found backup files
|
|
debug:
|
|
msg: |
|
|
Found {{ existing_dumps.files | length }} dump files
|
|
Created full backup archive: /tmp/forgejo-full-backup-{{ ansible_date_time.date }}.tar.gz
|
|
|
|
- name: Fetch dump file to ops server (if exists)
|
|
synchronize:
|
|
mode: pull
|
|
src: "{{ (existing_dumps.files | sort(attribute='mtime', reverse=true) | first).path }}"
|
|
dest: /opt/forgejo-backup/
|
|
delegate_to: asxpio-ops
|
|
when: existing_dumps.files | length > 0
|
|
ignore_errors: true
|
|
|
|
- name: Fetch full backup archive to ops server
|
|
synchronize:
|
|
mode: pull
|
|
src: /tmp/forgejo-full-backup-{{ ansible_date_time.date }}.tar.gz
|
|
dest: /opt/forgejo-backup/
|
|
delegate_to: asxpio-ops
|
|
become: true
|
|
|
|
- name: Display backup location
|
|
debug:
|
|
msg: |
|
|
Backup files transferred to asxpio-ops:/opt/forgejo-backup/
|
|
|
|
Files:
|
|
- forgejo-full-backup-{{ ansible_date_time.date }}.tar.gz (complete backup)
|
|
{% if existing_dumps.files | length > 0 %}
|
|
- {{ (existing_dumps.files | sort(attribute='mtime', reverse=true) | first).path | basename }} (dump file)
|
|
{% endif %}
|
|
|
|
Next step: Run restore playbook
|
|
ansible-playbook playbooks/restore-forgejo.yaml
|