Backuping gitea.

This commit is contained in:
Julien Palard 2022-10-09 23:03:53 +02:00
parent daed7462ad
commit a48fb10a30
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
6 changed files with 68 additions and 5 deletions

View File

@ -38,3 +38,6 @@
path: deb.afpy.org/
- remote: deb2.afpy.org:/var/www/
path: deb.afpy.org/
- remote: gitea1.afpy.org:/var/backups/
path: git.afpy.org/

View File

@ -0,0 +1,55 @@
---
# It's possible to see some info about the timer using:
#
# systemctl list-timers gitea-backup
# systemctl status gitea-backup.service
- name: Create backup script
copy:
dest: /usr/local/bin/gitea-backup.sh
owner: root
group: root
mode: 0750
content: |
#!/bin/sh
rm -fr /var/backups/gitea
mkdir /var/backups/gitea
systemctl stop gitea
chown git:git /var/backups/gitea/
GITEA_WORK_DIR=/var/lib/gitea sudo -u git --preserve-env=GITEA_WORK_DIR gitea dump -c /etc/gitea/app.ini --file /var/backups/gitea/gitea.zip
sudo -u git pg_dump gitea > /var/backups/gitea/gitea.sql
chown root:root /var/backups/gitea
chmod 700 /var/backups/gitea/
systemctl start gitea
- name: Create backup service
copy:
dest: /etc/systemd/system/gitea-backup.service
owner: root
group: root
mode: 0644
content: |
[Unit]
Description=Backup gitea
[Service]
Type=oneshot
ExecStart=/usr/local/bin/gitea-backup.sh
- name: Create backup timer
copy:
dest: /etc/systemd/system/gitea-backup.timer
owner: root
group: root
mode: 0644
content: |
[Unit]
Description=Daily gitea backup
[Timer]
OnCalendar=*-*-* 03:00:00
- name: Start backup timer
service: name=gitea-backup.timer state=started daemon_reload=yes

View File

@ -1,13 +1,13 @@
---
- name: Setup app.ini
notify: restart gitea
template:
src: app.ini.j2
dest: /etc/gitea/app.ini
mode: 0640
owner: root
group: git
notify: restart gitea
- name: Setup gitea systemd service
template:
@ -16,6 +16,7 @@
owner: root
group: root
mode: 0644
notify: restart gitea
- name: extra links footer
copy:

View File

@ -6,5 +6,8 @@
- include: config.yml
tags: config
- include: backup.yml
tags: backup
- name: Start gitea
service: name=gitea enabled=yes state=started daemon_reload=yes

View File

@ -4,6 +4,7 @@ After=syslog.target
After=network.target
Wants=postgresql.service
After=postgresql.service
Requires=gitea-backup.timer
[Service]
RestartSec=2s

View File

@ -1,4 +1,4 @@
30 3 * * * root /usr/bin/rsnapshot -c /etc/rsnapshot_{{ rsnapshot_name }}.conf daily
0 3 * * 1 root /usr/bin/rsnapshot -c /etc/rsnapshot_{{ rsnapshot_name }}.conf weekly
30 2 1 * * root /usr/bin/rsnapshot -c /etc/rsnapshot_{{ rsnapshot_name }}.conf monthly
0 1 1 1 * root /usr/bin/rsnapshot -c /etc/rsnapshot_{{ rsnapshot_name }}.conf yearly
0 5 * * * root /usr/bin/rsnapshot -c /etc/rsnapshot_{{ rsnapshot_name }}.conf daily
30 4 * * 1 root /usr/bin/rsnapshot -c /etc/rsnapshot_{{ rsnapshot_name }}.conf weekly
0 4 1 * * root /usr/bin/rsnapshot -c /etc/rsnapshot_{{ rsnapshot_name }}.conf monthly
30 3 1 1 * root /usr/bin/rsnapshot -c /etc/rsnapshot_{{ rsnapshot_name }}.conf yearly