File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 11#! /bin/bash
22
3+ set -euo pipefail
4+
35# MIT License
46
57# Copyright (c) 2023 Oliver Brunsmann
@@ -56,26 +58,29 @@ backup_db() {
5658 local backup_dir=" $6 "
5759
5860 echo " Backing up $db "
59- mysqldump \
61+ if mysqldump \
6062 --user=" $db_user " --password=" $db_pass " \
6163 --host=" $db_host " \
6264 --single-transaction \
6365 --skip-lock-tables \
64- $db | gzip > " $backup_dir /$timestamp /$db .sql.gz"
65-
66- echo " Backup of $db completed"
66+ " $db " | gzip > " $backup_dir /$timestamp /$db .sql.gz" ; then
67+ echo " Backup of $db completed"
68+ else
69+ echo " Backup of $db failed" >&2
70+ return 1
71+ fi
6772}
6873export -f backup_db
6974
7075# Get list of all databases
7176databases=$( mysql -h $db_host -u $db_user --password=" $db_pass " -e " SHOW DATABASES;" | grep -Ev " (Database|information_schema|performance_schema|mysql|sys|vapor)" )
7277
7378# Run export job
74- echo " $databases " | parallel -j $max_parallel backup_db {} $db_user $db_pass $db_host $timestamp $backup_dir
79+ echo " $databases " | parallel --halt soon,fail=1 -j " $max_parallel " backup_db {} " $db_user " " $db_pass " " $db_host " " $timestamp " " $backup_dir "
7580
7681# Clean up old backups
7782echo " Cleaning up old backups"
7883cleanup_old_backups $backup_dir
7984
8085# Done
81- echo -e " \n\nBackup completed\n"
86+ echo -e " \n\nBackup completed\n"
You can’t perform that action at this time.
0 commit comments