From 0ffd14ccf01928a2a872ff459e8d5a70a34e2fe9 Mon Sep 17 00:00:00 2001 From: L3D Date: Sat, 13 Feb 2021 05:32:27 +0100 Subject: [PATCH] create backup direcotry create a backup folder and move the gitea backup to backup.yml --- defaults/main.yml | 2 ++ tasks/backup.yml | 32 ++++++++++++++++++++++++++++++++ tasks/install.yml | 22 ---------------------- tasks/main.yml | 6 +++++- 4 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 tasks/backup.yml diff --git a/defaults/main.yml b/defaults/main.yml index 4ae6768..7f2baba 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -86,3 +86,5 @@ gitea_repo_exclude_vendored: true gitea_repo_indexer_max_file_size: 1048576 gitea_extra_config: "" + +gitea_backup_location: "{{ gitea_home }}/backups/" diff --git a/tasks/backup.yml b/tasks/backup.yml new file mode 100644 index 0000000..e3b8ab3 --- /dev/null +++ b/tasks/backup.yml @@ -0,0 +1,32 @@ +--- +- name: Get service facts + service_facts: + +- block: + - name: Stopping gitea before upgrade + service: + name: gitea + state: stopped + + - name: "Create backup directory" + file: + path: "{{ item }}" + state: directory + owner: "{{ gitea_user }}" + group: "{{ gitea_group }}" + mode: 'u=rwx,g=rx,o=' + with_items: + - "{{ gitea_backup_location }}" + + - name: Backing up gitea before upgrade + command: + cmd: "gitea dump -c /etc/gitea/gitea.ini" + chdir: "{{ gitea_backup_location }}" + become: true + become_method: su + become_user: "{{ gitea_user }}" + become_flags: "-s /bin/sh" + when: + - ansible_facts.services["gitea.service"] is defined + - ansible_facts.services["gitea.service"].state == "running" + - gitea_active_version.stdout != gitea_version diff --git a/tasks/install.yml b/tasks/install.yml index 2f4f143..474df90 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -18,28 +18,6 @@ retries: 5 delay: 2 -- name: Get service facts - service_facts: - -- block: - - name: Stopping gitea before upgrade - service: - name: gitea - state: stopped - - - name: Backing up gitea before upgrade - command: - cmd: "gitea dump -c /etc/gitea/gitea.ini" - chdir: /var/backups/ - become: true - become_method: su - become_user: "{{ gitea_user }}" - become_flags: "-s /bin/sh" - when: - - ansible_facts.services["gitea.service"] is defined - - ansible_facts.services["gitea.service"].state == "running" - - gitea_active_version.stdout != gitea_version - - block: - name: Download gitea archive get_url: diff --git a/tasks/main.yml b/tasks/main.yml index a148ff8..f687d9f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -17,7 +17,11 @@ failed_when: false when: gitea_version_check|bool -- include: install.yml +- name: backup gitea before update + include_tasks: backup.yml + +- name: install or update gitea + include_tasks: install.yml - include: create_user.yml