diff --git a/backup.yml b/backup.yml index bfbe555..f8e61b2 100644 --- a/backup.yml +++ b/backup.yml @@ -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/ diff --git a/roles/gitea/tasks/backup.yml b/roles/gitea/tasks/backup.yml new file mode 100644 index 0000000..d6a8e8d --- /dev/null +++ b/roles/gitea/tasks/backup.yml @@ -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 diff --git a/roles/gitea/tasks/config.yml b/roles/gitea/tasks/config.yml index ab52fba..017a485 100644 --- a/roles/gitea/tasks/config.yml +++ b/roles/gitea/tasks/config.yml @@ -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: diff --git a/roles/gitea/tasks/main.yml b/roles/gitea/tasks/main.yml index e3ba23c..b5d6e8b 100644 --- a/roles/gitea/tasks/main.yml +++ b/roles/gitea/tasks/main.yml @@ -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 diff --git a/roles/gitea/templates/gitea.service.j2 b/roles/gitea/templates/gitea.service.j2 index d05c0ba..9945446 100644 --- a/roles/gitea/templates/gitea.service.j2 +++ b/roles/gitea/templates/gitea.service.j2 @@ -4,6 +4,7 @@ After=syslog.target After=network.target Wants=postgresql.service After=postgresql.service +Requires=gitea-backup.timer [Service] RestartSec=2s diff --git a/roles/rsnapshoter/templates/rsnapshot.cron.j2 b/roles/rsnapshoter/templates/rsnapshot.cron.j2 index 7a45b46..e4315d1 100644 --- a/roles/rsnapshoter/templates/rsnapshot.cron.j2 +++ b/roles/rsnapshoter/templates/rsnapshot.cron.j2 @@ -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