From 8d30bb6eb684bba7f34aa5bced8aaf4930ce903b Mon Sep 17 00:00:00 2001 From: Marius Alwan Meyer <22202402+sporqist@users.noreply.github.com> Date: Fri, 28 Apr 2023 21:42:01 +0000 Subject: [PATCH] Backup und Restore, falls der Server nicht wieder hoch kommt --- tasks/main.yaml | 99 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 27 deletions(-) diff --git a/tasks/main.yaml b/tasks/main.yaml index e47b221..b7d457e 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -41,33 +41,78 @@ enabled: yes state: started -- name: Upload Environment File - ansible.builtin.template: - src: environment.env.j2 - dest: "/opt/gitea/environment.env" - owner: root - mode: 0600 - register: gitea_env +- name: Backup Files + block: + - name: Stop Gitea for Backup + community.docker.docker_compose: + project_src: /opt/gitea + state: present + stopped: true -- name: Upload docker-compose.yaml - ansible.builtin.template: - src: docker-compose.yaml.j2 - dest: /opt/gitea/docker-compose.yaml - owner: root - mode: 0600 - register: gitea_container + - 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: Create / Recreate Gitea container - community.docker.docker_compose: - project_src: /opt/gitea - state: present - restarted: true - when: gitea_env.changed or gitea_container.changed +- name: Apply Changes + block: + - name: Upload Environment File + ansible.builtin.template: + src: environment.env.j2 + 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 - ansible.builtin.uri: - url: "https://{{ gitea.hostname }}.{{ gitea.domain }}" - register: _result - until: _result.status == 200 - retries: 60 - delay: 10 + - name: Upload docker-compose.yaml + ansible.builtin.template: + src: docker-compose.yaml.j2 + dest: /opt/gitea/docker-compose.yaml + owner: root + mode: 0600 + 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