From e832987fcab8d5af3c2c8665e2e9120aa9b3fe33 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 4 Jun 2019 14:19:57 -0700 Subject: [PATCH] Add db backups to gitea This isn't added as a separate role because it heavily relies on the gitea deployment specific (docker-compose, service names, etc). If we end up running more services with docker-compose and databases we can probably make this reconsumable. Change-Id: I7b9084a8a90a86f73f5b24de505978d3f286850b --- playbooks/roles/gitea/tasks/main.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/playbooks/roles/gitea/tasks/main.yaml b/playbooks/roles/gitea/tasks/main.yaml index 90bb04db09..3d0f0b5b61 100644 --- a/playbooks/roles/gitea/tasks/main.yaml +++ b/playbooks/roles/gitea/tasks/main.yaml @@ -134,3 +134,26 @@ minute: 37 hour: 12 weekday: 0 +- name: Create db backup dest + file: + state: directory + path: /var/backups/gitea-mariadb + mode: 0700 + owner: root + group: root +- name: Set up cron job to backup the database + cron: + name: gitea-db-backup + state: present + user: root + job: > + /usr/bin/docker-compose -f /etc/gitea-docker/docker-compose.yaml exec -T mariadb + bash -c '/usr/bin/mysqldump --opt --ignore-table mysql.event --all-databases --single-transaction -uroot -p"$MYSQL_ROOT_PASSWORD"' | + gzip -9 > /var/backups/gitea-mariadb/gitea-mariadb.sql.gz + minute: 42 + hour: 4 +- name: Rotate db backups + include_role: + name: logrotate + vars: + logrotate_file_name: /var/backups/gitea-mariadb/gitea-mariadb.sql.gz