From d6b06a38fb4e64c75b16bd1fe74b0c209c03892a Mon Sep 17 00:00:00 2001 From: staffadmin Date: Mon, 4 Aug 2025 23:53:41 +0200 Subject: [PATCH] [Add backup full gitea + docker] --- backup-gitea.yml | 53 +++++++++++++++++++++++++++++++--------- backup.yml | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 12 deletions(-) diff --git a/backup-gitea.yml b/backup-gitea.yml index 2ce54c5..dbb816c 100644 --- a/backup-gitea.yml +++ b/backup-gitea.yml @@ -1,23 +1,44 @@ - hosts: tower vars: dockerapps_path: /opt/dockerapps + gitea_conf: /appdata/gitea/gitea/ + #backup: /backup/gitea + + gitea_db: /appdata/gitea/gitea-db/gitea-db-pg.sql # become: true gather_facts: false tasks: + - ansible.builtin.file: + path: "{{ dockerapps_path }}/backup/gitea" + state: directory + # mode: '0755' #/opt/dockerapps/appdata/gitea/gitea/gitea-dump-*.zip - # - name: DUMP gitea conf - # community.docker.docker_container_exec: - # container: gitea - # command: gitea dump -c /data/gitea/conf/app.ini - # user: git - # chdir: /data - # register: result_gitea_conf + - name: DUMP gitea conf + community.docker.docker_container_exec: + container: gitea + command: gitea dump -c /data/gitea/conf/app.ini + user: git + chdir: /data - # - name: Print stdout - # ansible.builtin.debug: - # var: result_gitea_conf.stdout + - ansible.builtin.find: + paths: "{{ dockerapps_path }}{{ gitea_conf }}" + patterns: 'gitea-dump-*.zip' + register: result_gitea_conf + + - name: Print stdout + ansible.builtin.debug: + var: result_gitea_conf + + - name: Copy file with owner and permissions + ansible.builtin.copy: + src: "{{ item.path }}" + dest: "{{ dockerapps_path }}/backup/gitea/{{ item.path.split('/')[-1]}}" + loop: "{{ result_gitea_conf.files }}" + # owner: foo + # group: foo + # mode: '0644' #! need root @@ -30,10 +51,18 @@ # chdir: "{{ dockerapps_path }}" register: result_gitea_db - - name: Print stdout - ansible.builtin.debug: + - ansible.builtin.debug: var: result_gitea_db.stdout + - name: Copy file with owner and permissions + become: true + ansible.builtin.copy: + src: "{{ dockerapps_path }}{{ gitea_db }}" + dest: "{{ dockerapps_path }}/backup/gitea/{{ gitea_db.split('/')[-1] }}" + # owner: "{{ }}" + # group: foo + # mode: '0644' + # docker exec -u git -w /data/ gitea gitea dump -c /data/gitea/conf/app.ini # mv /opt/dockerapps/appdata/gitea/gitea/gitea-dump-*.zip /opt/dockerapps/backup/ diff --git a/backup.yml b/backup.yml index 7fce668..f4c537a 100644 --- a/backup.yml +++ b/backup.yml @@ -3,6 +3,9 @@ # become: true gather_facts: false vars: + dockerapps_path: /opt/dockerapps + gitea_conf: /appdata/gitea/gitea/ + gitea_db: /appdata/gitea/gitea-db/gitea-db-pg.sql user: sgratias user_mail: stephane.gratiasquiquandon@gmail.com token: !vault | @@ -15,6 +18,9 @@ 3565333032326133326232326633386332633639373862313463 tasks: +############ +###! DOCKER COMPOSE FILE +############ # - debug: # msg: "test ok" @@ -109,6 +115,63 @@ delegate_to: localhost + +############# +#! GITEA +############ + + - ansible.builtin.file: + path: "{{ dockerapps_path }}/backup/gitea" + state: directory + + # mode: '0755' +#/opt/dockerapps/appdata/gitea/gitea/gitea-dump-*.zip + - name: DUMP gitea conf + community.docker.docker_container_exec: + container: gitea + command: gitea dump -c /data/gitea/conf/app.ini + user: git + chdir: /data + + - ansible.builtin.find: + paths: "{{ dockerapps_path }}{{ gitea_conf }}" + patterns: 'gitea-dump-*.zip' + register: result_gitea_conf + + - name: Print stdout + ansible.builtin.debug: + var: result_gitea_conf + + - name: Copy file with owner and permissions + ansible.builtin.copy: + src: "{{ item.path }}" + dest: "{{ dockerapps_path }}/backup/gitea/{{ item.path.split('/')[-1]}}" + loop: "{{ result_gitea_conf.files }}" + # owner: foo + # group: foo + # mode: '0644' + + +#! need root +# root@scaleway:/opt/dockerapps/appdata/gitea/gitea-db/gitea-db-pg.sql + + - name: PG_DUMP postgresql db + community.docker.docker_container_exec: + container: gitea-db + command: pg_dump -U root gitea -f /var/lib/postgresql/data/gitea-db-pg.sql + # chdir: "{{ dockerapps_path }}" + register: result_gitea_db + + - ansible.builtin.debug: + var: result_gitea_db.stdout + + - name: Copy file with owner and permissions + become: true + ansible.builtin.copy: + src: "{{ dockerapps_path }}{{ gitea_db }}" + dest: "{{ dockerapps_path }}/backup/gitea/{{ gitea_db.split('/')[-1] }}" + + # curl -u "$username:$password" -H "Title: HTTPS Certificats" -H "ta:closed_lock_with_key" -d "*.jingoh.fr Less than 20 days" https://alert.jingoh.fr/scaleway # when: cert.not_after - ansible_date_time.iso8601_basic >