From ede6cd537eddb6790ee04a4589e70bc68ab99f95 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 9 Oct 2022 14:42:33 +0200 Subject: [PATCH] feat: fail backup on script errors --- scripts/ftp_backup.sh | 2 +- scripts/mysql_backup.sh | 4 ++-- scripts/postgres_backup.sh | 4 ++-- scripts/prefilebackup | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/ftp_backup.sh b/scripts/ftp_backup.sh index 696cc90..f0c0f76 100644 --- a/scripts/ftp_backup.sh +++ b/scripts/ftp_backup.sh @@ -11,7 +11,7 @@ lftp -u "$FTP_USER","$FTP_PASSWORD" $FTP_HOST < $BACKUP_DIR/$MYSQL_BACKUP_DATABASE.sqldump +mkdir --parents $BACKUP_DIR || exit 1 +mysqldump --single-transaction --host=$MYSQL_BACKUP_HOST --user=$MYSQL_BACKUP_USER --password=$MYSQL_BACKUP_PASSWORD $MYSQL_BACKUP_DATABASE > $BACKUP_DIR/$MYSQL_BACKUP_DATABASE.sqldump || exit 1 echo "Mysql database backup finished" diff --git a/scripts/postgres_backup.sh b/scripts/postgres_backup.sh index 1d6d2a7..d72f8c6 100644 --- a/scripts/postgres_backup.sh +++ b/scripts/postgres_backup.sh @@ -4,7 +4,7 @@ BACKUP_DIR="/backup/database" echo "Starting to backup postgres database" -mkdir --parents $BACKUP_DIR -PGPASSWORD=$PG_PASSWORD pg_dump --host=$PG_HOST --username=$PG_USER $PG_DATABASE > $BACKUP_DIR/$PG_DATABASE.sqldump +mkdir --parents $BACKUP_DIR || exit 1 +PGPASSWORD=$PG_PASSWORD pg_dump --host=$PG_HOST --username=$PG_USER $PG_DATABASE > $BACKUP_DIR/$PG_DATABASE.sqldump || exit 1 echo "Postgres database backup finished" diff --git a/scripts/prefilebackup b/scripts/prefilebackup index c73c930..4462015 100644 --- a/scripts/prefilebackup +++ b/scripts/prefilebackup @@ -1,13 +1,13 @@ #!/usr/bin/env sh if [[ -n "$DO_FTP_BACKUP" ]]; then - sh /usr/local/etc/urbackup/ftp_backup.sh + sh /usr/local/etc/urbackup/ftp_backup.sh || exit 1 fi if [[ -n "$DO_MYSQL_BACKUP" ]]; then - sh /usr/local/etc/urbackup/mysql_backup.sh + sh /usr/local/etc/urbackup/mysql_backup.sh || exit 1 fi if [[ -n "$DO_POSTGRES_BACKUP" ]]; then - sh /usr/local/etc/urbackup/postgres_backup.sh + sh /usr/local/etc/urbackup/postgres_backup.sh || exit 1 fi