From 71ea49b7ace096dbd0d1f7c178f7db3ee63522b5 Mon Sep 17 00:00:00 2001 From: L3D Date: Sun, 21 Mar 2021 17:10:42 +0100 Subject: [PATCH] modify backup on upgrade (#81) * create backup direcotry create a backup folder and move the gitea backup to backup.yml * make the backup on update optional Documentation and introduction of the variable `gitea_backup_on_upgrade: false` * change become_method to sudo change become_method to sudo as suggested by @wzzrd. removed become_flags. * Full path to gitea binary in backup task. thanks to @wzzrd --- README.md | 4 ++++ defaults/main.yml | 3 +++ tasks/backup.yml | 30 ++++++++++++++++++++++++++++++ tasks/install.yml | 22 ---------------------- tasks/main.yml | 7 ++++++- 5 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 tasks/backup.yml diff --git a/README.md b/README.md index 02dcc0b..3ad1a7a 100644 --- a/README.md +++ b/README.md @@ -162,6 +162,10 @@ As this will only deploy config files, fail2ban already has to be installed or o * `gitea_repo_exclude_vendored`: Exclude vendored files from the index. Default: `true` * `gitea_repo_indexer_max_file_size`: Maximum size of files to be indexed (in bytes). Default: `1048576` (1 MB) +### backup on upgrade +* `gitea_backup_on_upgrade`: Optionally a backup can be created with every update of gitea. Default: `false` +* `gitea_backup_location`: Where to store the gitea backup if one is created with this role. Default: `{{ gitea_home }}/backups/` + ## Contributing Don't hesitate to create a pull request, and when in doubt you can reach me on Twitter [@thomas_maurice](https://twitter.com/thomas_maurice). diff --git a/defaults/main.yml b/defaults/main.yml index 5f76ee2..8a2941d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -88,3 +88,6 @@ gitea_repo_indexer_max_file_size: 1048576 gitea_log_level: Info gitea_extra_config: "" + +gitea_backup_on_upgrade: false +gitea_backup_location: "{{ gitea_home }}/backups/" diff --git a/tasks/backup.yml b/tasks/backup.yml new file mode 100644 index 0000000..fa8e9ab --- /dev/null +++ b/tasks/backup.yml @@ -0,0 +1,30 @@ +--- +- 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: "/usr/local/bin/gitea dump -c /etc/gitea/gitea.ini" + chdir: "{{ gitea_backup_location }}" + become: true + become_user: "{{ gitea_user }}" + 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..dfb5a58 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -17,7 +17,12 @@ failed_when: false when: gitea_version_check|bool -- include: install.yml +- name: backup gitea before update + include_tasks: backup.yml + when: gitea_backup_on_upgrade|bool + +- name: install or update gitea + include_tasks: install.yml - include: create_user.yml