forked from AFPy/infra
59 lines
1.3 KiB
YAML
59 lines
1.3 KiB
YAML
---
|
|
|
|
# It's possible to see some info about the timer using:
|
|
#
|
|
# systemctl list-timers gitea-backup
|
|
# systemctl status gitea-backup.service
|
|
|
|
|
|
- name: Create backup directory
|
|
file:
|
|
state: directory
|
|
mode: 0700
|
|
owner: git
|
|
group: git
|
|
path: /var/backups/gitea/
|
|
|
|
- name: Create backup script
|
|
copy:
|
|
dest: /usr/local/bin/gitea-backup.sh
|
|
owner: root
|
|
group: root
|
|
mode: 0750
|
|
content: |
|
|
#!/bin/sh
|
|
systemctl stop gitea
|
|
sudo --user git gitea --work-path /var/lib/gitea --config /etc/gitea/app.ini dump --file /var/backups/gitea/gitea.zip
|
|
sudo --user git pg_dump --clean gitea > /var/backups/gitea/gitea.sql
|
|
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
|