TAR() {
local cmd="tar --create --gzip"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" --file $1"
cmd+=" \"$1\""
shift
done
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" 2>&1 | tee -a \"${LOGFILE}\" || true"
else
cmd+=" >/dev/null 2>&1 || true"
local cmd="mysqldump --all_databases --routines --triggers --add-drop-database"
cmd+=" --add-drop-table --complete-insert --extended-insert --lock-tables"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" --log-error=\"${errorlog}\""
cmd+=" | gzip -9"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" > \"${dumpfile}\""
if [[ -e "${errorlog}" ]] ; then
if [[ -s "${errorlog}" ]] ; then
cmd="gzip -9 \"${errorlog}\""
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd="gzip -9 --verbose \"${errorlog}\""
fi
info "Executing: ${cmd}"
debug "Dumping PostgreSQL globals ..."
local dumpfile="${BACKUP_DIR}/postgres.@globals.dump.sql.gz"
local cmd="su - postgres -c \"pg_dumpall"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" --globals-only --clean --encoding=utf-8 --disable-triggers --if-exists\""
cmd+=" | gzip -9"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" > \"${dumpfile}\""
debug "Dumping PostgreSQL database '${CYAN}${db}${NORMAL}' ..."
dumpfile="${BACKUP_DIR}/postgres.${db}.dump.sql.gz"
cmd="su - postgres -c \"pg_dump"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" --blobs --clean --create --encoding=utf-8 --disable-triggers --if-exists '${db}'\""
cmd+=" | gzip -9"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" > \"${dumpfile}\""
empty_line
info "Dumping OpenLDAP Config -> '${CYAN}${dumpfile}${NORMAL}' ..."
local cmd="ldapsearch -Y EXTERNAL -Q -LLL -o ldif-wrap=no -H ldapi:/// -b \"cn=config\""
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" -v"
fi
cmd+=" | gzip -9"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" > \"${dumpfile}\""
info "Dumping OpenLDAP Datenbank '${CYAN}${dn}${NORMAL}' -> '${CYAN}${dumpfile}${NORMAL}' ..."
cmd="ldapsearch -Y EXTERNAL -Q -LLL -o ldif-wrap=no -H ldapi:///"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" -v"
fi
cmd+=" -b \"${dn}\" '+' '*' | gzip -9"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" > \"${dumpfile}\""
empty_line
info "Syncing backup to '${GREEN}${rhost}${NORMAL}:${CYAN}${BACKUP_HOSTDIR}${NORMAL}' ..."
cmd="rsync --archive --hard-links --delete --stats"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd+=" --verbose"
fi
cmd+=" \"${BACKUP_HOSTDIR}\" \"${rhost}:${BACKUP_PARENTDIR}\""
info "Downloading '${CYAN}${url}${NORMAL}' ..."
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
wget "${url}"
else
wget -q "${url}"
cd "${WWW_BASE}"
local cmd="tar -c"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" && "${VERBOSE}" -gt '1' ]] ; then
cmd+=" --verbose"
fi
cmd+=" --file \"${backup_file}\" --bzip2 nextcloud"
cd "${TEMP_DIR}"
info "Unpacking '${GREEN}${archive}${NORMAL}' ..."
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" && "${VERBOSE}" -gt '1' ]] ; then
tar xfvj "${archive}"
else
tar xfj "${archive}"
info "Stopping '${CYAN}${SERVICE_NAME}${NORMAL}' ..."
systemctl stop "${SERVICE_NAME}"
- if [[ "${VERBOSE}" == 'y' ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
systemctl status "${SERVICE_NAME}" || true
fi
info "Starting '${CYAN}${SERVICE_NAME}${NORMAL}' ..."
systemctl start "${SERVICE_NAME}"
- if [[ "${VERBOSE}" == 'y' ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
systemctl status "${SERVICE_NAME}" || true
fi
)
# Standard global variables
-VERBOSE="n"
+VERBOSE=""
DEBUG="n"
DO_ASK="n"
SIMULATE="n"
shift
;;
-v|--verbose)
- VERBOSE="y"
+ if [[ -z "${VERBOSE}" ]] ; then
+ VERBOSE='0'
+ fi
+ VERBOSE=$(( VERBOSE + 1 ))
shift
;;
-q|--quiet)
done
fi
- if [[ "${VERBOSE}" == "y" && "${QUIET}" == "y" ]] ; then
+ if [[ "${VERBOSE}" && "${QUIET}" == "y" ]] ; then
error "The options '${RED}--verbose${NORMAL}' and '${RED}--quiet${NORMAL}' are mutually exclusive."
echo
usage >&2
#------------------------------------------------------------------------------
debug() {
- if [[ "${VERBOSE}" != "y" ]] ; then
+ if [[ -z "${VERBOSE}" ]] ; then
return 0
fi
local ts=$(my_date)
RM() {
local cmd="rm $*"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd="rm --verbose $*"
fi
if [[ "${SIMULATE}" == "y" ]] ; then
return
fi
debug "Executing: ${cmd}"
- if [[ "${VERBOSE}" != "y" ]] ; then
+ if [[ -z "${VERBOSE}" ]] ; then
rm "$@"
else
rm --verbose "$@"
#------------------------------------------------------------------------------
purge() {
- if [[ "${VERBOSE}" != "y" ]] ; then
+ if [[ -z "${VERBOSE}" ]] ; then
rm "$@"
else
rm --verbose "$@"
MKDIR() {
local cmd="mkdir $*"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd="mkdir --verbose $*"
fi
if [[ "${SIMULATE}" == "y" ]] ; then
CP() {
local cmd="cp $*"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd="cp --verbose $*"
fi
if [[ "${SIMULATE}" == "y" ]] ; then
return
fi
debug "Executing: ${cmd}"
- if [[ "${VERBOSE}" != "y" ]] ; then
+ if [[ -z "${VERBOSE}" ]] ; then
cp "$@"
else
cp --verbose "$@"
MV() {
local cmd="mv $*"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd="mv --verbose $*"
fi
if [[ "${SIMULATE}" == "y" ]] ; then
return
fi
debug "Executing: ${cmd}"
- if [[ "${VERBOSE}" != "y" ]] ; then
+ if [[ -z "${VERBOSE}" ]] ; then
mv "$@"
else
mv --verbose "$@"
CHOWN() {
local cmd="chown $*"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd="chown --verbose $*"
fi
if [[ "${SIMULATE}" == "y" ]] ; then
return
fi
debug "Executing: ${cmd}"
- if [[ "${VERBOSE}" != "y" ]] ; then
+ if [[ -n "${VERBOSE}" ]] ; then
chown "$@"
else
chown --verbose "$@"
CHMOD() {
local cmd="chmod $*"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd="chmod --verbose $*"
fi
if [[ "${SIMULATE}" == "y" ]] ; then
return
fi
debug "Executing: ${cmd}"
- if [[ "${VERBOSE}" != "y" ]] ; then
+ if [[ -z "${VERBOSE}" ]] ; then
chmod "$@"
else
chmod --verbose "$@"
LN() {
local cmd="ln $*"
- if [[ "${VERBOSE}" == "y" ]] ; then
+ if [[ "${VERBOSE}" ]] ; then
cmd="ln --verbose $*"
fi
if [[ "${SIMULATE}" == "y" ]] ; then
return
fi
debug "Executing: ${cmd}"
- if [[ "${VERBOSE}" != "y" ]] ; then
+ if [[ -z "${VERBOSE}" ]] ; then
ln "$@"
else
ln --verbose "$@"