From ec78b22ae10782bc146f30fab2e0df09f2ce15c3 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Sun, 25 Dec 2016 10:56:32 +0100 Subject: Quiet mode option for use in crontabs was added. --- Bash/mysql-database-backup.sh | 14 +++++++++++++- Bash/virtualhosts-backup.sh | 18 +++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'Bash') diff --git a/Bash/mysql-database-backup.sh b/Bash/mysql-database-backup.sh index 39b0a3d..746f215 100755 --- a/Bash/mysql-database-backup.sh +++ b/Bash/mysql-database-backup.sh @@ -6,8 +6,20 @@ # This database backup script goes through each database (except the excluded # # databases in DATABASE_EXCLUDED) and creates a bzip2 compressed backup file. # # # +# OPTION [-q]: Enable quiet mode for use in crontab. # +# # #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# +#=============================================================================== +# Parsing command-line arguments with the getopts shell builtin +#=============================================================================== +while getopts :q option +do + case $option in + q) ARGUMENT_QUIETMODE=true ;; + esac +done + #=============================================================================== # Define database login credentials and excluded databases #=============================================================================== @@ -43,6 +55,6 @@ DATABASES=$(mysql --user="${DATABASE_USERNAME}" --password="${DATABASE_PASSWORD} # Loop through all database names and create compressed database backup #=============================================================================== for database in ${DATABASES}; do - echo "[INFO] Creating compressed backup for database ${database} [...]" + [ ! $ARGUMENT_QUIETMODE ] && echo "[INFO] Creating compressed backup for database ${database} [...]" mysqldump --lock-all-tables --user="${DATABASE_USERNAME}" --password="${DATABASE_PASSWORD}" "${database}" | bzip2 > $(printf "${DIRECTORY_FILE}" "${database}") done \ No newline at end of file diff --git a/Bash/virtualhosts-backup.sh b/Bash/virtualhosts-backup.sh index 140039e..ecdcb3b 100755 --- a/Bash/virtualhosts-backup.sh +++ b/Bash/virtualhosts-backup.sh @@ -23,8 +23,20 @@ # |--- config # # |--- htdocs # # # +# OPTION [-q]: Enable quiet mode for use in crontab. # +# # #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# +#=============================================================================== +# Parsing command-line arguments with the getopts shell builtin +#=============================================================================== +while getopts :q option +do + case $option in + q) ARGUMENT_QUIETMODE=true ;; + esac +done + #=============================================================================== # Define backup main directories #=============================================================================== @@ -55,13 +67,13 @@ for username in $(find ${DIRECTORY_FROM}* -maxdepth 0 -type d -exec basename {} DIRECTORY_USER="${DIRECTORY_ROOT}${DIRECTORY_PATH}${username}/" DIRECTORY_FILE="${DIRECTORY_USER}%s.tar.bz2" - echo "[INFO] Entering directory: ${DIRECTORY_FROM}${username}/:" + [ ! $ARGUMENT_QUIETMODE ] && echo "[INFO] Entering directory: ${DIRECTORY_FROM}${username}/:" #=============================================================================== # Create backup sub path directory if not exists #=============================================================================== if [ ! -d "${DIRECTORY_USER}" ]; then - echo "[INFO] Creating backup directory for user $username [...]" + [ ! $ARGUMENT_QUIETMODE ] && echo "[INFO] Creating backup directory for user $username [...]" mkdir "${DIRECTORY_USER}" fi @@ -69,7 +81,7 @@ for username in $(find ${DIRECTORY_FROM}* -maxdepth 0 -type d -exec basename {} # Loop through all virtualhosts within the user directory #=============================================================================== for virtualhost in $(find ${DIRECTORY_FROM}${username}/* -maxdepth 0 -type d -exec basename {} \;); do - echo "[INFO] Creating compressed backup for virtualhost $virtualhost [...]" + [ ! $ARGUMENT_QUIETMODE ] && echo "[INFO] Creating compressed backup for virtualhost $virtualhost [...]" tar --create --bzip2 --file "$(printf "${DIRECTORY_FILE}" "${virtualhost}")" --directory "${DIRECTORY_FROM}${username}/" "${virtualhost}" done done \ No newline at end of file -- cgit v1.2.3