ansible
This commit is contained in:
parent
7974e36c1b
commit
b81f7e15b2
41 changed files with 1632 additions and 0 deletions
129
ansible/roles/forgejo_restore/tasks/main.yaml
Normal file
129
ansible/roles/forgejo_restore/tasks/main.yaml
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
---
|
||||
- name: Stop Forgejo container
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /opt/forgejo
|
||||
state: stopped
|
||||
ignore_errors: true
|
||||
|
||||
- name: Find backup dump file locally
|
||||
find:
|
||||
paths: "{{ backup_dest_dir }}"
|
||||
patterns: "gitea-dump-*.zip"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
register: local_dump_file
|
||||
|
||||
- name: Find additional backup file locally
|
||||
find:
|
||||
paths: "{{ backup_dest_dir }}"
|
||||
patterns: "forgejo-additional-*.tar.gz"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
register: local_additional_file
|
||||
|
||||
- name: Fail if no backup files found
|
||||
fail:
|
||||
msg: "No backup files found in {{ backup_dest_dir }}. Please run backup-forgejo.yaml first."
|
||||
when: local_dump_file.files | length == 0
|
||||
|
||||
- name: Copy dump backup to server
|
||||
copy:
|
||||
src: "{{ local_dump_file.files[0].path }}"
|
||||
dest: /tmp/forgejo-dump.zip
|
||||
mode: '0644'
|
||||
|
||||
- name: Copy additional backup to server
|
||||
copy:
|
||||
src: "{{ local_additional_file.files[0].path }}"
|
||||
dest: /tmp/forgejo-additional.tar.gz
|
||||
mode: '0644'
|
||||
when: local_additional_file.files | length > 0
|
||||
|
||||
- name: Extract Forgejo dump
|
||||
unarchive:
|
||||
src: /tmp/forgejo-dump.zip
|
||||
dest: /opt/forgejo/
|
||||
remote_src: true
|
||||
creates: /opt/forgejo/app.ini
|
||||
|
||||
- name: Extract additional backup
|
||||
unarchive:
|
||||
src: /tmp/forgejo-additional.tar.gz
|
||||
dest: /tmp/forgejo-restore/
|
||||
remote_src: true
|
||||
when: local_additional_file.files | length > 0
|
||||
|
||||
- name: Ensure data directory exists
|
||||
file:
|
||||
path: /opt/forgejo/data
|
||||
state: directory
|
||||
mode: '0755'
|
||||
|
||||
- name: Copy database from dump to data directory
|
||||
copy:
|
||||
src: /opt/forgejo/data/gitea.db
|
||||
dest: /opt/forgejo/data/gitea.db
|
||||
remote_src: true
|
||||
force: true
|
||||
ignore_errors: true
|
||||
|
||||
- name: Copy repository data from additional backup
|
||||
synchronize:
|
||||
src: /tmp/forgejo-restore/srv/gitea/data/
|
||||
dest: /opt/forgejo/data/
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
when: local_additional_file.files | length > 0
|
||||
ignore_errors: true
|
||||
|
||||
- name: Copy SSH keys from additional backup
|
||||
synchronize:
|
||||
src: /tmp/forgejo-restore/var/lib/forgejo/.ssh/
|
||||
dest: /opt/forgejo/data/.ssh/
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
when: local_additional_file.files | length > 0
|
||||
ignore_errors: true
|
||||
|
||||
- name: Set correct ownership for Forgejo data
|
||||
file:
|
||||
path: /opt/forgejo/data
|
||||
owner: 1000
|
||||
group: 1000
|
||||
recurse: true
|
||||
|
||||
- name: Start Forgejo container
|
||||
community.docker.docker_compose_v2:
|
||||
project_src: /opt/forgejo
|
||||
state: present
|
||||
|
||||
- name: Wait for Forgejo to be healthy
|
||||
uri:
|
||||
url: http://localhost:{{ forgejo_http_port }}/
|
||||
status_code: 200
|
||||
retries: 15
|
||||
delay: 5
|
||||
register: result
|
||||
until: result.status == 200
|
||||
|
||||
- name: Clean up temporary files
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: absent
|
||||
loop:
|
||||
- /tmp/forgejo-dump.zip
|
||||
- /tmp/forgejo-additional.tar.gz
|
||||
- /tmp/forgejo-restore
|
||||
|
||||
- name: Display restore information
|
||||
debug:
|
||||
msg: |
|
||||
Forgejo restore completed successfully!
|
||||
|
||||
Forgejo is now running at:
|
||||
- Internal: http://localhost:{{ forgejo_http_port }}
|
||||
- External: https://{{ forgejo_domain }}
|
||||
|
||||
Next steps:
|
||||
1. Test git operations: git clone https://{{ forgejo_domain }}/user/repo.git
|
||||
2. Test SSH access: git clone git@{{ forgejo_domain }}:user/repo.git
|
||||
3. Test web interface at https://{{ forgejo_domain }}
|
||||
4. Register runners with the new instance
|
||||
Loading…
Add table
Add a link
Reference in a new issue