Backup und Restore, falls der Server nicht wieder hoch kommt

This commit is contained in:
Marius Alwan Meyer 2023-04-28 21:42:01 +00:00
parent f2bbe10aa2
commit 8d30bb6eb6

View File

@ -41,7 +41,25 @@
enabled: yes enabled: yes
state: started state: started
- name: Upload Environment File - name: Backup Files
block:
- name: Stop Gitea for Backup
community.docker.docker_compose:
project_src: /opt/gitea
state: present
stopped: true
- name: Backup Gitea Directory
ansible.builtin.copy:
src: /opt/gitea
dest: "/opt/gitea.backup@{{ ansible_date_time.iso8601 }}"
remote_src: true
directory_mode: true
register: backup
- name: Apply Changes
block:
- name: Upload Environment File
ansible.builtin.template: ansible.builtin.template:
src: environment.env.j2 src: environment.env.j2
dest: "/opt/gitea/environment.env" dest: "/opt/gitea/environment.env"
@ -49,7 +67,7 @@
mode: 0600 mode: 0600
register: gitea_env register: gitea_env
- name: Upload docker-compose.yaml - name: Upload docker-compose.yaml
ansible.builtin.template: ansible.builtin.template:
src: docker-compose.yaml.j2 src: docker-compose.yaml.j2
dest: /opt/gitea/docker-compose.yaml dest: /opt/gitea/docker-compose.yaml
@ -57,17 +75,44 @@
mode: 0600 mode: 0600
register: gitea_container register: gitea_container
- name: Create / Recreate Gitea container - name: Create / Recreate Gitea
community.docker.docker_compose: community.docker.docker_compose:
project_src: /opt/gitea project_src: /opt/gitea
state: present state: present
restarted: true restarted: true
when: gitea_env.changed or gitea_container.changed when: gitea_env.changed or gitea_container.changed
- name: Check if {{ gitea.hostname }}.{{ gitea.domain }} is available and returning status 200 - name: Check if {{ gitea.hostname }}.{{ gitea.domain }} is available and returning status 200
ansible.builtin.uri: ansible.builtin.uri:
url: "https://{{ gitea.hostname }}.{{ gitea.domain }}" url: "https://{{ gitea.hostname }}.{{ gitea.domain }}"
register: _result register: _result
until: _result.status == 200 until: _result.status == 200
retries: 60 retries: 30
delay: 10 delay: 2
rescue:
- name: Stop Gitea for Backup
community.docker.docker_compose:
project_src: /opt/gitea
state: present
stopped: true
- name: Restore Gitea Directory from Backup
ansible.builtin.copy:
src: "{{ backup.dest }}"
dest: "{{ backup.src }}"
remote_src: true
- name: Create / Recreate Gitea
community.docker.docker_compose:
project_src: /opt/gitea
state: present
restarted: true
always:
- name: Check if {{ gitea.hostname }}.{{ gitea.domain }} is available and returning status 200
ansible.builtin.uri:
url: "https://{{ gitea.hostname }}.{{ gitea.domain }}"
register: _result
until: _result.status == 200
retries: 30
delay: 2