Remove LOG_FILE and USER_LOG_FILE config directives and allow user to force logging into specific file instead of syslog by using the --log-file parameter
This commit is contained in:
parent
f22b634607
commit
fbe3702c90
|
@ -27,17 +27,6 @@ REMOTE_USER="%h-%u"
|
||||||
RSYNC_OPTIONS="--acls --hard-links --xattrs"
|
RSYNC_OPTIONS="--acls --hard-links --xattrs"
|
||||||
#RSYNC_OPTIONS="--hard-links --xattrs"
|
#RSYNC_OPTIONS="--hard-links --xattrs"
|
||||||
|
|
||||||
# Global log file to use when running as root
|
|
||||||
LOG_FILE="/var/log/rs-backup.log"
|
|
||||||
|
|
||||||
# Log filename (only basename) of the log file to use when running as a
|
|
||||||
# normal user. The file will be placed inside the user's home directory.
|
|
||||||
# Leave empty if you don't want any per-user log file.
|
|
||||||
# The user log file will only be written when the user originally invoked
|
|
||||||
# the script, not if his home directory is backed up during a full system
|
|
||||||
# backup run by root
|
|
||||||
USER_LOG_FILE="rs-backup.user.log"
|
|
||||||
|
|
||||||
# Name of the file inside the users' home directories
|
# Name of the file inside the users' home directories
|
||||||
# containing the patterns for matching files to include or exclude.
|
# containing the patterns for matching files to include or exclude.
|
||||||
# The format is the same as the global 'include-files' config file
|
# The format is the same as the global 'include-files' config file
|
||||||
|
|
|
@ -44,6 +44,8 @@ _VERSION=$(rs-version version)
|
||||||
_GLOBAL_INCLUSION_PATTERN_FILE="/etc/rs-backup/include-files"
|
_GLOBAL_INCLUSION_PATTERN_FILE="/etc/rs-backup/include-files"
|
||||||
_FORCED_INCLUSION_PATTERN_FILE=""
|
_FORCED_INCLUSION_PATTERN_FILE=""
|
||||||
_SKIP_HOME_DIRS=false
|
_SKIP_HOME_DIRS=false
|
||||||
|
_FALLBACK_LOG_FILE="/var/log/rs-backup.log"
|
||||||
|
_FALLBACK_USER_LOG_FILE="rs-backup.user.log"
|
||||||
_FORCED_LOG_FILE=""
|
_FORCED_LOG_FILE=""
|
||||||
_QUIET_MODE=false
|
_QUIET_MODE=false
|
||||||
_VERBOSE_MODE=false
|
_VERBOSE_MODE=false
|
||||||
|
@ -101,7 +103,7 @@ Options:
|
||||||
performed, no additional home directories will be
|
performed, no additional home directories will be
|
||||||
backed up
|
backed up
|
||||||
-l, --log-level=NUM Set log level to NUM (between 0 and 4)
|
-l, --log-level=NUM Set log level to NUM (between 0 and 4)
|
||||||
--log-file=FILE Set a different log file location
|
--log-file=FILE Log to this file instead of syslog
|
||||||
-f, --force-run Force rs-backup to run, even if a lock file exists
|
-f, --force-run Force rs-backup to run, even if a lock file exists
|
||||||
-q, --quiet Don't print any error messages or warnings to the
|
-q, --quiet Don't print any error messages or warnings to the
|
||||||
screen (only write to log file)
|
screen (only write to log file)
|
||||||
|
@ -116,20 +118,19 @@ HELP
|
||||||
# Usage: write_log <log level> <log message>
|
# Usage: write_log <log level> <log message>
|
||||||
#
|
#
|
||||||
write_log() {
|
write_log() {
|
||||||
local log_msg
|
local log_msg="${2}"
|
||||||
local log_date
|
local log_date="[$(date)]"
|
||||||
local log_dest
|
local log_dest
|
||||||
local use_syslog=false
|
local use_syslog=false
|
||||||
local logger="logger -t $(basename $0)"
|
local logger="logger -t $(basename $0)"
|
||||||
|
|
||||||
command -v logger > /dev/null 2>&1
|
command -v logger > /dev/null 2>&1
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ] && [ "${_FORCED_LOG_FILE}" == "" ]; then
|
||||||
use_syslog=true
|
use_syslog=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $1 -gt 0 ] && [ $1 -le $LOG_LEVEL ]; then
|
if [ $1 -gt 0 ] && [ $1 -le $LOG_LEVEL ]; then
|
||||||
if $use_syslog; then
|
if $use_syslog; then
|
||||||
log_msg="${2}"
|
|
||||||
case $1 in
|
case $1 in
|
||||||
1) $logger -p err "${log_msg}" ;;
|
1) $logger -p err "${log_msg}" ;;
|
||||||
2) $logger -p warning "${log_msg}" ;;
|
2) $logger -p warning "${log_msg}" ;;
|
||||||
|
@ -147,23 +148,21 @@ write_log() {
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# if no syslog facility exists, go the cumbersome way...
|
# if no syslog facility exists, go the cumbersome way...
|
||||||
if ! $use_syslog; then
|
if ! $use_syslog || [ "${_FORCED_LOG_FILE}" != "" ]; then
|
||||||
log_date="[$(date)]"
|
|
||||||
full_log_msg="${log_date} ${log_msg}"
|
|
||||||
|
|
||||||
if [ "${_FORCED_LOG_FILE}" != "" ]; then
|
if [ "${_FORCED_LOG_FILE}" != "" ]; then
|
||||||
log_dest=${_FORCED_LOG_FILE}
|
log_dest=${_FORCED_LOG_FILE}
|
||||||
elif [ $(id -u) -eq 0 ]; then
|
elif [ $(id -u) -eq 0 ]; then
|
||||||
log_dest=${LOG_FILE}
|
log_dest=${_FALLBACK_LOG_FILE}
|
||||||
elif [ "${HOME}" != "" ] && [ "${USER_LOG_FILE}" != "" ]; then
|
elif [ "${HOME}" != "" ] && [ "${_FALLBACK_USER_LOG_FILE}" != "" ]; then
|
||||||
log_dest=${HOME}/${USER_LOG_FILE}
|
log_dest=${HOME}/${_FALLBACK_USER_LOG_FILE}
|
||||||
else
|
else
|
||||||
echo "WARNING: Couldn't determine valid log file location, using '/var/tmp'..." >&2
|
echo -e "\e[1mWARNING: Couldn't determine valid log file location, using '/var/tmp'...\e[0m" >&2
|
||||||
log_dest="/var/tmp/${LOG_FILE}"
|
log_dest="/var/tmp/${LOG_FILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
touch "${log_dest}" 2> /dev/null
|
||||||
if ! test_file_perms "w" "${log_dest}"; then
|
if ! test_file_perms "w" "${log_dest}"; then
|
||||||
echo "ERROR: Couldn't open log file for writing, redirecting to STDOUT!" >&2
|
echo -e "\e[1m\e[91mERROR: Couldn't open log file for writing, redirecting to STDOUT!\e[0m" >&2
|
||||||
echo "${log_date} ${log_msg}" >&1
|
echo "${log_date} ${log_msg}" >&1
|
||||||
else
|
else
|
||||||
echo "${log_date} ${log_msg}" >> "${log_dest}"
|
echo "${log_date} ${log_msg}" >> "${log_dest}"
|
||||||
|
|
Loading…
Reference in New Issue