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,33 +41,78 @@
enabled: yes enabled: yes
state: started state: started
- name: Upload Environment File - name: Backup Files
ansible.builtin.template: block:
src: environment.env.j2 - name: Stop Gitea for Backup
dest: "/opt/gitea/environment.env" community.docker.docker_compose:
owner: root project_src: /opt/gitea
mode: 0600 state: present
register: gitea_env stopped: true
- name: Upload docker-compose.yaml - name: Backup Gitea Directory
ansible.builtin.template: ansible.builtin.copy:
src: docker-compose.yaml.j2 src: /opt/gitea
dest: /opt/gitea/docker-compose.yaml dest: "/opt/gitea.backup@{{ ansible_date_time.iso8601 }}"
owner: root remote_src: true
mode: 0600 directory_mode: true
register: gitea_container register: backup
- name: Create / Recreate Gitea container - name: Apply Changes
community.docker.docker_compose: block:
project_src: /opt/gitea - name: Upload Environment File
state: present ansible.builtin.template:
restarted: true src: environment.env.j2
when: gitea_env.changed or gitea_container.changed dest: "/opt/gitea/environment.env"
owner: root
mode: 0600
register: gitea_env
- name: Check if {{ gitea.hostname }}.{{ gitea.domain }} is available and returning status 200 - name: Upload docker-compose.yaml
ansible.builtin.uri: ansible.builtin.template:
url: "https://{{ gitea.hostname }}.{{ gitea.domain }}" src: docker-compose.yaml.j2
register: _result dest: /opt/gitea/docker-compose.yaml
until: _result.status == 200 owner: root
retries: 60 mode: 0600
delay: 10 register: gitea_container
- name: Create / Recreate Gitea
community.docker.docker_compose:
project_src: /opt/gitea
state: present
restarted: true
when: gitea_env.changed or gitea_container.changed
- 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
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