diff --git a/roles/borg_client/templates/backup-mysql.sh.j2 b/roles/borg_client/templates/backup-mysql.sh.j2 index 9aee38dc718614c5bdcf52c745c0509f80cec2b2..84cd957d8074bc7221a1d0c92955af68f7e18804 100644 --- a/roles/borg_client/templates/backup-mysql.sh.j2 +++ b/roles/borg_client/templates/backup-mysql.sh.j2 @@ -1,5 +1,7 @@ #!/bin/bash +set -e + mysql_opts="--defaults-file={{mysql_backup_defaults}}" backupdir="{{mysql_backup_dir}}" diff --git a/roles/borg_client/templates/backup-postgres.sh.j2 b/roles/borg_client/templates/backup-postgres.sh.j2 index ccb34fa993d70cea0e6f78f0f0d69f61796cef8d..a87e2ad2d2984ec4514c7c54fbf8c2e8b406d26f 100644 --- a/roles/borg_client/templates/backup-postgres.sh.j2 +++ b/roles/borg_client/templates/backup-postgres.sh.j2 @@ -3,7 +3,8 @@ # Script to backup all postgres databases individually # # Requires local login with `postgres` user and either trusted or peer auth. -# + +set -e DBLIST=($(sudo -u postgres psql -d postgres -qt -c 'SELECT datname from pg_database')) for db in "${DBLIST[@]}"; do diff --git a/roles/borg_client/templates/borg-backup.sh.j2 b/roles/borg_client/templates/borg-backup.sh.j2 index c0d55a7738cd5a4320ec75ba051afb45f940c8b4..bfddba08c13743868b17e364caf40e0983a979f5 100644 --- a/roles/borg_client/templates/borg-backup.sh.j2 +++ b/roles/borg_client/templates/borg-backup.sh.j2 @@ -40,9 +40,11 @@ cleanup() { trap cleanup EXIT # Dump databases to /root/backup-{postgres,mysql} before taking a btrfs snapshot -systemctl is-active postgresql && /usr/local/bin/backup-postgres.sh || true -if systemctl is-active mysqld || systemctl is-active mariadb; then - /usr/local/bin/backup-mysql.sh || true +if systemctl is-active postgresql; then + /usr/local/bin/backup-postgres.sh +fi +if systemctl is-active mariadb; then + /usr/local/bin/backup-mysql.sh fi if is_btrfs "$src"; then