db-koji02: make sure backup uses all cpus

Signed-off-by: Kevin Fenzi <kevin@scrye.com>
This commit is contained in:
Kevin Fenzi 2020-04-07 03:49:08 +00:00 committed by Pierre-Yves Chibon
parent 4c85106614
commit bd50c6e4bc
2 changed files with 22 additions and 0 deletions

View file

@ -0,0 +1,16 @@
#!/bin/bash
# Backup a database *locally* to /backups/.
# Sleep a bit so we do not have a thundering herd on db hosts
sleep $[ ( $RANDOM % 7200 ) + 1 ]s
DB=$1
# Make our latest backup
# Make it use a limited number of threads because pxz will use all the
# cpus which causes pg_dump to starve which causes...
/usr/bin/pg_dump --exclude-table-data=sessions -C $DB | /usr/bin/pxz -T24 > /backups/$DB-$(date +%F).dump.xz
# Also, delete the backup from a few days ago.
rm -f /backups/$DB-$(date --date="1 days ago" +%F).dump.xz

View file

@ -105,6 +105,12 @@
tags:
- postgresql
- name: Copy over backup scriplet
copy: src=backup-database dest=/usr/local/bin/backup-database mode=0755
when: not inventory_hostname.startswith('db-koji02')
tags:
- postgresql
- name: Copy over backup scriplet
copy: src=backup-database dest=/usr/local/bin/backup-database mode=0755
when: inventory_hostname.startswith('db-koji02')