diff options
author | Thomas Lange <code@nerdmind.de> | 2016-12-25 10:56:32 +0100 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2016-12-25 10:56:32 +0100 |
commit | ec78b22ae10782bc146f30fab2e0df09f2ce15c3 (patch) | |
tree | 2047ccf9d5bd123342c3ebac28028e58a87379ce /Bash/virtualhosts-backup.sh | |
parent | 7eaddf4194142b3dd95f697dbca38791e2c16650 (diff) | |
download | snippets-ec78b22ae10782bc146f30fab2e0df09f2ce15c3.tar.gz snippets-ec78b22ae10782bc146f30fab2e0df09f2ce15c3.tar.xz snippets-ec78b22ae10782bc146f30fab2e0df09f2ce15c3.zip |
Quiet mode option for use in crontabs was added.
Diffstat (limited to 'Bash/virtualhosts-backup.sh')
-rwxr-xr-x | Bash/virtualhosts-backup.sh | 18 |
1 files changed, 15 insertions, 3 deletions
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,9 +23,21 @@ # |--- 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 #=============================================================================== DIRECTORY_ROOT="/mnt/data/backups/virtualhosts/" @@ -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 |