From fe5eccd3c72b099f6caa0cacf4e71d807a4bea18 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Mon, 29 Jun 2015 13:26:41 +0000 Subject: [PATCH] Add backups for taiga.cloud.fp.o. --- inventory/backups | 1 + .../host_vars/taiga.cloud.fedoraproject.org | 3 ++ roles/taiga/files/backup-database | 10 +++++++ roles/taiga/tasks/main.yml | 29 ++++++++++--------- roles/taiga/templates/cron-backup-database | 1 + 5 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 roles/taiga/files/backup-database create mode 100644 roles/taiga/templates/cron-backup-database diff --git a/inventory/backups b/inventory/backups index 189970f980..bc3fc05757 100644 --- a/inventory/backups +++ b/inventory/backups @@ -21,4 +21,5 @@ copr-be.cloud.fedoraproject.org copr-fe.cloud.fedoraproject.org copr-keygen.cloud.fedoraproject.org value01.phx2.fedoraproject.org +taiga.cloud.fedoraproject.org taskotron01.qa.fedoraproject.org diff --git a/inventory/host_vars/taiga.cloud.fedoraproject.org b/inventory/host_vars/taiga.cloud.fedoraproject.org index cb1fdfe203..998dc859bd 100644 --- a/inventory/host_vars/taiga.cloud.fedoraproject.org +++ b/inventory/host_vars/taiga.cloud.fedoraproject.org @@ -13,6 +13,9 @@ public_ip: 209.132.184.50 root_auth_users: ralph maxamillion description: taiga frontend server +host_backup_targets: ['/backups'] +dbs_to_backup: ['taiga'] + volumes: - volume_id: 4a99a0b3-6812-4c09-af1e-6313a467e3ec device: /dev/vdc diff --git a/roles/taiga/files/backup-database b/roles/taiga/files/backup-database new file mode 100644 index 0000000000..3f6e7d8fb1 --- /dev/null +++ b/roles/taiga/files/backup-database @@ -0,0 +1,10 @@ +#!/bin/bash +# Backup a database *locally* to /backups/. + +DB=$1 + +# Make our latest backup +/usr/bin/pg_dump -C $DB | /usr/bin/xz > /backups/$DB-$(date +%F).dump.xz + +# Also, delete the backup from a few days ago. +rm -f /backups/$DB-$(date --date="3 days ago" +%F).dump.xz diff --git a/roles/taiga/tasks/main.yml b/roles/taiga/tasks/main.yml index 1339ba6bd1..b7127182b3 100644 --- a/roles/taiga/tasks/main.yml +++ b/roles/taiga/tasks/main.yml @@ -56,20 +56,21 @@ # notify: restart postgresql # tags: taiga -## If we want to do backups, we can enable these three tasks -#- name: Ensure postgres has a place to backup to -# file: dest=/backups state=directory owner=postgres -# tags: taiga -# -#- name: Copy over backup scriplet -# copy: src=backup-database dest=/usr/local/bin/backup-database mode=0755 -# tags: taiga -# -#- name: Set up some cronjobs to backup databases as configured -# template: > -# src=cron-backup-database -# dest=/etc/cron.d/cron-backup-database-taiga -# tags: taiga +- name: Ensure postgres has a place to backup to + file: dest=/backups state=directory owner=postgres + tags: taiga + +- name: Copy over backup scriplet + copy: src=backup-database dest=/usr/local/bin/backup-database mode=0755 + tags: taiga + +- name: Set up some cronjobs to backup databases as configured + template: > + src=cron-backup-database + dest=/etc/cron.d/cron-backup-database-{{ item }} + with_items: + - taiga + tags: taiga - name: Set postgresql-server to run on boot service: name=postgresql state=running enabled=yes diff --git a/roles/taiga/templates/cron-backup-database b/roles/taiga/templates/cron-backup-database new file mode 100644 index 0000000000..ce3c52d7d4 --- /dev/null +++ b/roles/taiga/templates/cron-backup-database @@ -0,0 +1 @@ +0 0 * * * postgres /usr/local/bin/backup-database {{ item }}