From 6817fe0ff94c281769b510e965c8ed11598a425d Mon Sep 17 00:00:00 2001 From: Marius Alwan Meyer <22202402+sporqist@users.noreply.github.com> Date: Sat, 29 Apr 2023 19:52:00 +0000 Subject: [PATCH] [FIX] Repariere den Backup-Wiederherstellungsprozess --- handlers/main.yaml | 22 ++++++++++++++++++++ tasks/main.yaml | 50 ++++++++++++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/handlers/main.yaml b/handlers/main.yaml index 283dafa..ad32af1 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -1,3 +1,25 @@ +- name: Stop Gitea for Backup + community.docker.docker_compose: + project_src: /opt/gitea + state: present + stopped: true + ignore_errors: true + listen: + - Backup Gitea + notify: + - Ensure Gitea is running + +- name: Backup Gitea Directory + ansible.builtin.copy: + src: /opt/gitea/ + dest: "/opt/gitea.backup@{{ lookup('pipe', 'date --utc --iso-8601=seconds') }}" + mode: preserve + remote_src: true + directory_mode: true + listen: + - Backup Gitea + register: backup + - name: Ensure Gitea is running community.docker.docker_compose: project_src: /opt/gitea diff --git a/tasks/main.yaml b/tasks/main.yaml index d5d4bd0..e71b162 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -39,22 +39,30 @@ enabled: true state: started -- name: Stop Gitea for Backup - community.docker.docker_compose: - project_src: /opt/gitea - state: present - stopped: true +- name: Check if environment.env will get changed + ansible.builtin.template: + src: environment.env.j2 + dest: "/opt/gitea/environment.env" + owner: root + mode: "600" + register: env_diff + check_mode: true notify: - - Ensure Gitea is running + - Backup Gitea -- name: Backup Gitea Directory - ansible.builtin.copy: - src: /opt/gitea/ - dest: "/opt/gitea.backup@{{ lookup('pipe', 'date --utc --iso-8601=seconds') }}" - mode: "700" - remote_src: true - directory_mode: true - register: backup +- name: Check if docker-compose.yaml will get changed + ansible.builtin.template: + src: docker-compose.yaml.j2 + dest: /opt/gitea/docker-compose.yaml + owner: root + mode: "600" + register: docker_compose_diff + check_mode: true + notify: + - Backup Gitea + +- name: Execute Handlers before changing configfiles + meta: flush_handlers - name: Upload Environment File ansible.builtin.template: @@ -69,11 +77,10 @@ dest: /opt/gitea/docker-compose.yaml owner: root mode: "600" - validate: /usr/bin/docker compose -f %s config -q notify: - Output Docker Compose State -- name: Try to reach Gitea +- name: Try to start and reach Gitea block: - name: Start Gitea @@ -97,11 +104,16 @@ notify: - Ensure Gitea is running + - name: Clean up Gitea Directory before restoring Backup + ansible.builtin.file: + path: /opt/gitea + state: absent + - name: Restore Gitea Directory from Backup ansible.builtin.copy: - src: "{{ backup.dest }}" - dest: "{{ backup.src }}" + src: "{{ backup.dest }}/" + dest: /opt/gitea remote_src: true - mode: "700" + mode: preserve notify: - Check Gitea HTTP Response