Add gitea restore command to deploy repos

This commit is contained in:
flyingscorpio@clevo 2022-04-10 13:33:00 +02:00
parent bef5897fe0
commit cdeeebac32
3 changed files with 39 additions and 4 deletions

View file

@ -1,5 +1,10 @@
---
- hosts: lime2
vars_prompt:
- name: push_latest_gitea_dump
prompt: Push latest gitea dump? [yes/no]
private: no
roles:
- role: common
tags: [mail, gitea, 2px, tunuifranken]

View file

@ -1,12 +1,14 @@
---
- include_vars: vault.yml
- name: Install git and gpg
- name: Install needed packages
become: true
apt:
name:
- git
- gpg
- unzip
- gpg # to verify binary
- acl # for become_user: git
state: present
- name: Create git group
@ -149,3 +151,33 @@
owner: git
group: git
mode: 0775
- name: Set today's string for zipfile name
set_fact:
today: "{{ ansible_date_time.year }}{{ ansible_date_time.month }}{{ ansible_date_time.day }}"
- name: Create gitea-dumps directory
become: true
file:
path: /home/git/gitea-dumps
state: directory
owner: git
group: git
mode: 0755
- name: Copy latest gitea_dump zipfile
become: true
copy:
src: "/tmp/gitea-dump-{{ today }}.zip"
dest: "/home/git/gitea-dumps/gitea-dump-{{ today }}.zip"
owner: git
group: git
mode: 0640
when: push_latest_gitea_dump == 'yes'
- name: Deploy repos
become: true
become_user: git
command:
cmd: "/home/git/gitea_backup.sh restore /home/git/gitea-dumps/gitea-dump-{{ today }}.zip"
creates: /home/git/gitea-repositories # when this dir exists, the command won't run, so we don't overwrite existing repos

View file

@ -66,8 +66,6 @@ do_restore() {
echo -n "Restoring $LOG_DIR..." && mv log/* "$LOG_DIR" && echo " OK."
echo -n "Restoring $REPO_DIR..." && mv repos/* "$REPO_DIR" && echo " OK."
echo -n "Changing ownership..." && chown -R git:git /etc/gitea/conf/app.ini /var/lib/gitea && echo " OK."
echo -n "MySQL password for $MYSQL_USER: "
read -rs mysql_passwd
echo -n "Restoring MySQL database..." && mysql --default-character-set=utf8mb4 -u"$MYSQL_USER" -p"$MYSQL_PW" "$MYSQL_DB" < gitea-db.sql && echo " OK."
restart_service
regenerate_hooks