Minor fixes before merging pull request

This commit is contained in:
Janek Bevendorff 2013-09-17 15:49:52 +02:00
parent d0b14bd268
commit 9bd20fefa1
2 changed files with 309 additions and 309 deletions

View File

@ -28,7 +28,7 @@ _SKIP_HOME_DIRS=false
_FORCED_LOG_FILE="" _FORCED_LOG_FILE=""
_QUIET_MODE=false _QUIET_MODE=false
_VERBOSE_MODE=false _VERBOSE_MODE=false
_SHOW_PROGRESS=false # Option to display file transfer progress _SHOW_PROGRESS=false
_DRY_RUN=false _DRY_RUN=false
_FORCE_RUN=false _FORCE_RUN=false
_ERROR_COUNT=0 _ERROR_COUNT=0
@ -42,7 +42,7 @@ _ERROR_COUNT=0
# #
# Usage: print_help # Usage: print_help
print_help() { print_help() {
cat << HELP cat << HELP
rs-backup-run version ${_VERSION} rs-backup-run version ${_VERSION}
Copyright (C) 2013 by Janek Bevendorff Copyright (C) 2013 by Janek Bevendorff
Web site: http://www.refining-linux.org/ Web site: http://www.refining-linux.org/
@ -59,31 +59,31 @@ user will be backed up.
Usage: $(basename $0) [OPTION]... Usage: $(basename $0) [OPTION]...
Options: Options:
-r, --remote-host=HOST The remote host to connect to -r, --remote-host=HOST The remote host to connect to
--remote-user=NAME The username to use for logging into the remote server --remote-user=NAME The username to use for logging into the remote server
(%h will be replaced with the host name of this (%h will be replaced with the host name of this
machine and %u with your username) machine and %u with your username)
--push-module=NAME The remote rsync server module --push-module=NAME The remote rsync server module
--ssh-options=OPTS Additional SSH options (will be merged with the default --ssh-options=OPTS Additional SSH options (will be merged with the default
options set in the rs-backup client-config file) ptions set in the rs-backup client-config file)
-o, --rsync-options=OPTS Additional options for rsync -o, --rsync-options=OPTS Additional options for rsync
-n, --dry-run Perform a test run (same as the --dry-run option for -n, --dry-run Perform a test run (same as the --dry-run option for
rsync). Enable --verbose mode for useful control output rsync). Enable --verbose mode for useful control output
-s, --no-home-dirs Don't back up home dirs, only perform global system -s, --no-home-dirs Don't back up home dirs, only perform global system
backup (root only) backup (root only)
-i, --include-from=FILE Specify an alternate inclusion pattern file -i, --include-from=FILE Specify an alternate inclusion pattern file
This will override the default setting. If the script This will override the default setting. If the script
is run as root, only the system backup will be is run as root, only the system backup will be
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 Set a different log file location
-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)
-v, --verbose Print all messages of the current debug level -v, --verbose Print all messages of the current debug level
-p, --progress Print file transfer information to the terminal -p, --progress Print file transfer information to the terminal
-h, --help Print this help and exit -h, --help Print this help and exit
HELP HELP
} }
@ -92,53 +92,53 @@ 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
local log_date local log_date
local log_dest local log_dest
if [ $1 -gt 0 ] && [ $1 -le $LOG_LEVEL ]; then if [ $1 -gt 0 ] && [ $1 -le $LOG_LEVEL ]; then
case $1 in case $1 in
1) log_msg="ERROR: ${2}" ;; 1) log_msg="ERROR: ${2}" ;;
2) log_msg="WARNING: ${2}" ;; 2) log_msg="WARNING: ${2}" ;;
3) log_msg="INFO: ${2}" ;; 3) log_msg="INFO: ${2}" ;;
*) log_msg="DEBUG: ${2}" ;; *) log_msg="DEBUG: ${2}" ;;
esac esac
log_date="[$(date)]" log_date="[$(date)]"
full_log_msg="${log_date} ${log_msg}" 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=${LOG_FILE}
elif [ "${HOME}" != "" ] && [ "${USER_LOG_FILE}" != "" ]; then elif [ "${HOME}" != "" ] && [ "${USER_LOG_FILE}" != "" ]; then
log_dest=${HOME}/${USER_LOG_FILE} log_dest=${HOME}/${USER_LOG_FILE}
else else
echo "WARNING: Couldn't determine valid log file location, using '/var/tmp'..." >&2 echo "WARNING: Couldn't determine valid log file location, using '/var/tmp'..." >&2
log_dest="/var/tmp/${LOG_FILE}" log_dest="/var/tmp/${LOG_FILE}"
fi fi
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 "ERROR: Couldn't open log file for writing, redirecting to STDOUT!" >&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}"
fi fi
if ! $_QUIET_MODE && [ $1 -eq 1 ]; then if ! $_QUIET_MODE && [ $1 -eq 1 ]; then
$_VERBOSE_MODE || $PRINT_ERRORS && echo "${log_msg}" >&2 $_VERBOSE_MODE || $PRINT_ERRORS && echo "${log_msg}" >&2
elif ! $_QUIET_MODE && [ $1 -le 2 ]; then elif ! $_QUIET_MODE && [ $1 -le 2 ]; then
$_VERBOSE_MODE || $PRINT_WARNINGS && echo "${log_msg}" >&2 $_VERBOSE_MODE || $PRINT_WARNINGS && echo "${log_msg}" >&2
elif ! $_QUIET_MODE && [ $1 -gt 2 ]; then elif ! $_QUIET_MODE && [ $1 -gt 2 ]; then
$_VERBOSE_MODE && echo "${log_msg}" >&1 $_VERBOSE_MODE && echo "${log_msg}" >&1
fi fi
fi fi
# Increase error count # Increase error count
if [ $1 -eq 1 ]; then if [ $1 -eq 1 ]; then
_ERROR_COUNT=$(($_ERROR_COUNT + 1)) _ERROR_COUNT=$(($_ERROR_COUNT + 1))
fi fi
} }
@ -147,19 +147,19 @@ write_log() {
# Usage: test_file_perms <mode: r|w|rw> <filename> # Usage: test_file_perms <mode: r|w|rw> <filename>
# #
test_file_perms() { test_file_perms() {
local perms=$1 local perms=$1
local filename=$2 local filename=$2
local result local result
if [ "${perms}" == "r" ]; then if [ "${perms}" == "r" ]; then
[ -f "${filename}" ] && [ -r "${filename}" ] [ -f "${filename}" ] && [ -r "${filename}" ]
elif [ "${perms}" == "w" ]; then elif [ "${perms}" == "w" ]; then
[ -f "${filename}" -a -w "${filename}" ] || [ ! -e "${2}" -a -w "$(dirname ${2})" ] [ -f "${filename}" -a -w "${filename}" ] || [ ! -e "${2}" -a -w "$(dirname ${2})" ]
elif [ "${perms}" == "rw" ]; then elif [ "${perms}" == "rw" ]; then
[ -f "${filename}" ] && [ -w "${filename}" ] && [ -r "${filename}" ] [ -f "${filename}" ] && [ -w "${filename}" ] && [ -r "${filename}" ]
fi fi
return $? return $?
} }
# Generate and return remote user name for SSH login # Generate and return remote user name for SSH login
@ -167,18 +167,18 @@ test_file_perms() {
# Usage: get_remote_username [<local username>] [<local hostname>] # Usage: get_remote_username [<local username>] [<local hostname>]
# #
get_remote_username() { get_remote_username() {
local username=$1 local username=$1
local hostname=$2 local hostname=$2
if [ "${username}" == "" ]; then if [ "${username}" == "" ]; then
username=$(id -un) username=$(id -un)
fi fi
if [ "${hostname}" == "" ]; then if [ "${hostname}" == "" ]; then
hostname=$(hostname) hostname=$(hostname)
fi fi
echo $(echo ${REMOTE_USER} | sed "s/%h/${hostname}/" | sed "s/%u/${username}/") echo $(echo ${REMOTE_USER} | sed "s/%h/${hostname}/" | sed "s/%u/${username}/")
} }
# Get a stripped down version of the /etc/passwd file with all non-system users, # Get a stripped down version of the /etc/passwd file with all non-system users,
@ -188,33 +188,33 @@ get_remote_username() {
# Usage: get_processed_passwd_file # Usage: get_processed_passwd_file
# #
get_processed_passwd_file() { get_processed_passwd_file() {
local line local line
local username local username
local uid local uid
local gid local gid
local home_dir local home_dir
local shell local shell
cat /etc/passwd | while read line; do cat /etc/passwd | while read line; do
uid=$(echo -n "${line}" | cut -d ":" -f 3) uid=$(echo -n "${line}" | cut -d ":" -f 3)
if [ $uid -lt 1000 ]; then if [ $uid -lt 1000 ]; then
continue continue
fi fi
home_dir=$(echo -n "${line}" | cut -d ":" -f 6) home_dir=$(echo -n "${line}" | cut -d ":" -f 6)
home_dir=$(realpath "${home_dir}") home_dir=$(realpath "${home_dir}")
if [ ! -d "${home_dir}" ]; then if [ ! -d "${home_dir}" ]; then
continue continue
fi fi
username=$(echo -n "${line}" | cut -d ":" -f 1) username=$(echo -n "${line}" | cut -d ":" -f 1)
gid=$(echo -n "${line}" | cut -d ":" -f 4) gid=$(echo -n "${line}" | cut -d ":" -f 4)
shell=$(echo -n "${line}" | cut -d ":" -f 7) shell=$(echo -n "${line}" | cut -d ":" -f 7)
echo "${username}:x:${uid}:${gid}::${home_dir}:${shell}" echo "${username}:x:${uid}:${gid}::${home_dir}:${shell}"
done done
} }
# Back up a directory. # Back up a directory.
@ -224,82 +224,82 @@ get_processed_passwd_file() {
# Usage: perform_backup <inclusion pattern file> <destination> [<username>] # Usage: perform_backup <inclusion pattern file> <destination> [<username>]
# #
perform_backup() { perform_backup() {
local inclusion_pattern_file=$1 local inclusion_pattern_file=$1
local destination=$2 local destination=$2
local username=$3 local username=$3
local msg local msg
local backup_cmd local backup_cmd
local ssh_cmd local ssh_cmd
local rsync_opts="${RSNC_OPTIONS}" local rsync_opts="${RSNC_OPTIONS}"
local exit_code local exit_code
local tee_device="/dev/tty" local tee_device="/dev/tty"
if $_DRY_RUN; then if $_DRY_RUN; then
rsync_opts+=" --dry-run" rsync_opts+=" --dry-run"
fi fi
if $_SHOW_PROGRESS; then if $_SHOW_PROGRESS; then
rsync_opts+=" --progress" # append to rsync_opts: preserves other options (e.g. --dry-run) rsync_opts+=" --progress" # append to rsync_opts: preserves other options (e.g. --dry-run)
elif $_VERBOSE_MODE; then # --progress implies --verbose elif $_VERBOSE_MODE; then # --progress implies --verbose
rsync_opts+=" --verbose" rsync_opts+=" --verbose"
else else
tee_device="/dev/null" tee_device="/dev/null"
rsync_opts+=" --quiet" rsync_opts+=" --quiet"
fi fi
if [ "${username}" == "" ]; then if [ "${username}" == "" ]; then
username=$(id -un) username=$(id -un)
fi fi
if [ "${_FORCED_INCLUSION_PATTERN_FILE}" != "" ]; then if [ "${_FORCED_INCLUSION_PATTERN_FILE}" != "" ]; then
inclusion_pattern_file=${_FORCED_INCLUSION_PATTERN_FILE} inclusion_pattern_file=${_FORCED_INCLUSION_PATTERN_FILE}
fi fi
if ! test_file_perms "r" "${inclusion_pattern_file}"; then if ! test_file_perms "r" "${inclusion_pattern_file}"; then
write_log 1 "Pattern file '${inclusion_pattern_file}' does not exist or is not readable!" write_log 1 "Pattern file '${inclusion_pattern_file}' does not exist or is not readable!"
return 1 return 1
fi fi
if [ "${SSH_OPTIONS}" != "" ]; then if [ "${SSH_OPTIONS}" != "" ]; then
ssh_cmd="ssh "$(echo -n "${SSH_OPTIONS}" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g') # added missing space ssh_cmd="ssh "$(echo -n "${SSH_OPTIONS}" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g') # added missing space
else else
ssh_cmd="ssh" ssh_cmd="ssh"
fi fi
backup_cmd="rsync \ backup_cmd="rsync \
--rsh=\"${ssh_cmd}\" \ --rsh=\"${ssh_cmd}\" \
--archive \ --archive \
--acls \ --acls \
--delete \ --delete \
--delete-excluded \ --delete-excluded \
--include-from=\"${inclusion_pattern_file}\" \ --include-from=\"${inclusion_pattern_file}\" \
--exclude=\"*\" \ --exclude=\"*\" \
${rsync_opts} \ ${rsync_opts} \
/ \ / \
\"${destination}\"" \"${destination}\""
write_log 4 "This is the command about to be run: $(echo ${backup_cmd})" write_log 4 "This is the command about to be run: $(echo ${backup_cmd})"
set -o pipefail set -o pipefail
if [ $(id -u) -eq 0 ] && [ "${username}" != "$(id -un)" ]; then if [ $(id -u) -eq 0 ] && [ "${username}" != "$(id -un)" ]; then
write_log 4 "Running backup with privileges of user '${username}' (UID: $(id -u ${username}))..." write_log 4 "Running backup with privileges of user '${username}' (UID: $(id -u ${username}))..."
msg=$(su - "${username}" -c "${backup_cmd}" 2>&1 | tee "${tee_device}") msg=$(su - "${username}" -c "${backup_cmd}" 2>&1 | tee "${tee_device}")
elif [ $(id -u) -ne 0 ] && [ "${username}" != "$(id -un)" ]; then elif [ $(id -u) -ne 0 ] && [ "${username}" != "$(id -un)" ]; then
write_log 1 "Cannot run run backup as user '${username}' (UID: $(id -u ${username}), missing root privileges!" write_log 1 "Cannot run run backup as user '${username}' (UID: $(id -u ${username}), missing root privileges!"
return 1 return 1
else else
msg=$(sh -c "${backup_cmd}" 2>&1 | tee "${tee_device}") msg=$(sh -c "${backup_cmd}" 2>&1 | tee "${tee_device}")
fi fi
exit_code=$? exit_code=$?
if [ ${exit_code} -ne 0 ]; then if [ ${exit_code} -ne 0 ]; then
write_log 1 "Backup failed! Error message: ${msg}" write_log 1 "Backup failed! Error message: ${msg}"
return ${exit_code} return ${exit_code}
else else
write_log 3 "Backup finished." write_log 3 "Backup finished."
fi fi
} }
# Back up selected system files # Back up selected system files
@ -307,51 +307,51 @@ perform_backup() {
# Usage: back_up_system # Usage: back_up_system
# #
back_up_system() { back_up_system() {
if [ $(id -u) -ne 0 ]; then if [ $(id -u) -ne 0 ]; then
write_log 1 "Cannot perform system backup unless run as root!" write_log 1 "Cannot perform system backup unless run as root!"
return 1 return 1
fi fi
write_log 4 "Entering directory '/root'..." write_log 4 "Entering directory '/root'..."
cd /root cd /root
if $_DRY_RUN; then if $_DRY_RUN; then
write_log 3 "Starting global system backup (DRY RUN)..." write_log 3 "Starting global system backup (DRY RUN)..."
else else
write_log 3 "Starting global system backup..." write_log 3 "Starting global system backup..."
fi fi
perform_backup "${_GLOBAL_INCLUSION_PATTERN_FILE}" "$(get_remote_username root)@${REMOTE_HOST}::${PUSH_MODULE}" perform_backup "${_GLOBAL_INCLUSION_PATTERN_FILE}" "$(get_remote_username root)@${REMOTE_HOST}::${PUSH_MODULE}"
} }
# Back up single home directory # Back up single home directory
# #
# Usage: back_up_single_home_dir <home dir> <username> # Usage: back_up_single_home_dir <home dir> <username>
# #
back_up_single_home_dir() { back_up_single_home_dir() {
local home_dir=$(realpath "${1}") local home_dir=$(realpath "${1}")
local username=$2 local username=$2
# Don't back up home directory if no files are marked for backup # Don't back up home directory if no files are marked for backup
if [ ! -f "${home_dir}/${INCLUSION_PATTERN_FILE}" ]; then if [ ! -f "${home_dir}/${INCLUSION_PATTERN_FILE}" ]; then
write_log 4 "Skipping '${home_dir}', because '${INCLUSION_PATTERN_FILE}' does not exist." write_log 4 "Skipping '${home_dir}', because '${INCLUSION_PATTERN_FILE}' does not exist."
return return
fi fi
# Also don't create a backup if no SSH key exists and no custom SSH options were specified # Also don't create a backup if no SSH key exists and no custom SSH options were specified
if [ ! -f "${home_dir}/.ssh/id_rsa" ] && [ ! -f "${home_dir}/.ssh/config" ] && [ "${SSH_OPTIONS}" == "" ]; then if [ ! -f "${home_dir}/.ssh/id_rsa" ] && [ ! -f "${home_dir}/.ssh/config" ] && [ "${SSH_OPTIONS}" == "" ]; then
write_log 4 "Skipping '${home_dir}', because no proper SSH key could be found." write_log 4 "Skipping '${home_dir}', because no proper SSH key could be found."
return return
fi fi
write_log 4 "Entering directory '${home_dir}'..." write_log 4 "Entering directory '${home_dir}'..."
cd "${home_dir}" cd "${home_dir}"
if $_DRY_RUN; then if $_DRY_RUN; then
write_log 3 "Starting backup of '${home_dir}' (DRY RUN)..." write_log 3 "Starting backup of '${home_dir}' (DRY RUN)..."
else else
write_log 3 "Starting backup of '${home_dir}'..." write_log 3 "Starting backup of '${home_dir}'..."
fi fi
perform_backup "${home_dir}/${INCLUSION_PATTERN_FILE}" "$(get_remote_username ${username})@${REMOTE_HOST}::${PUSH_MODULE}" "${username}" perform_backup "${home_dir}/${INCLUSION_PATTERN_FILE}" "$(get_remote_username ${username})@${REMOTE_HOST}::${PUSH_MODULE}" "${username}"
} }
# Back up all home dirs # Back up all home dirs
@ -359,11 +359,11 @@ back_up_single_home_dir() {
# Usage: back_up_home_dirs # Usage: back_up_home_dirs
# #
back_up_home_dirs() { back_up_home_dirs() {
write_log 3 "Starting backup of all home directories..." write_log 3 "Starting backup of all home directories..."
get_processed_passwd_file | while read line; do get_processed_passwd_file | while read line; do
back_up_single_home_dir "$(echo -n ${line} | cut -d ':' -f 6)" "$(echo -n ${line} | cut -d ':' -f 1)" back_up_single_home_dir "$(echo -n ${line} | cut -d ':' -f 6)" "$(echo -n ${line} | cut -d ':' -f 1)"
done done
} }
# Prase command line args # Prase command line args
@ -371,89 +371,89 @@ back_up_home_dirs() {
# Usage: parse_cmd_args <cmd arg line> # Usage: parse_cmd_args <cmd arg line>
# #
parse_cmd_args() { parse_cmd_args() {
local args local args
local name=$(basename $0) local name=$(basename $0)
if [ "$1" == "" ]; then if [ "$1" == "" ]; then
return return
fi fi
getopt -T > /dev/null getopt -T > /dev/null
if [ $? -ne 4 ]; then if [ $? -ne 4 ]; then
write_log 1 "Need GNU getopt for command line parameter parsing!" write_log 1 "Need GNU getopt for command line parameter parsing!"
exit 1; exit 1;
fi fi
args=$(getopt \ args=$(getopt \
-s sh \ -s sh \
-o "r:o:nsi:l:fqvph" \ -o "r:o:nsi:l:fqvph" \
-l "remote-host:,remote-user:,push-module:,ssh-options:,rsync-options:,dry-run,no-home-dirs,include-from:,log-level:,log-file:,force-run,quiet,verbose,progress,help" \ -l "remote-host:,remote-user:,push-module:,ssh-options:,rsync-options:,dry-run,no-home-dirs,include-from:,log-level:,log-file:,force-run,quiet,verbose,progress,help" \
-n "${name}" \ -n "${name}" \
-- "${@}") -- "${@}")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
eval set -- "${args}" eval set -- "${args}"
while true; do while true; do
case "$1" in case "$1" in
"-r"|"--remote-host") "-r"|"--remote-host")
REMOTE_HOST=$2 REMOTE_HOST=$2
shift 2 ;; shift 2 ;;
"--remote-user") "--remote-user")
REMOTE_USER=$2 REMOTE_USER=$2
shift 2 ;; shift 2 ;;
"--push-module") "--push-module")
PUSH_MODULE=$2 PUSH_MODULE=$2
shift 2 ;; shift 2 ;;
"--ssh-options") "--ssh-options")
SSH_OPTIONS="${SSH_OPTIONS} ${2}" SSH_OPTIONS="${SSH_OPTIONS} ${2}"
shift 2 ;; shift 2 ;;
"-o"|"--rsync-options") "-o"|"--rsync-options")
RSYNC_OPTIONS="${RSYNC_OPTIONS} $2" RSYNC_OPTIONS="${RSYNC_OPTIONS} $2"
shift 2 ;; shift 2 ;;
"-n"|"--dry-run") "-n"|"--dry-run")
_DRY_RUN=true _DRY_RUN=true
shift ;; shift ;;
"-s"|"--no-home-dirs") "-s"|"--no-home-dirs")
_SKIP_HOME_DIRS=true _SKIP_HOME_DIRS=true
shift ;; shift ;;
"-i"|"--include-from") "-i"|"--include-from")
# File must exist and be readable # File must exist and be readable
! test_file_perms "r" "${2}" && echo "$name: '${2}' does not exist or is not readable!" >&2 && exit 1 ! test_file_perms "r" "${2}" && echo "$name: '${2}' does not exist or is not readable!" >&2 && exit 1
_FORCED_INCLUSION_PATTERN_FILE=$2 _FORCED_INCLUSION_PATTERN_FILE=$2
_SKIP_HOME_DIRS=true _SKIP_HOME_DIRS=true
shift 2 ;; shift 2 ;;
"-l"|"--log-level") "-l"|"--log-level")
LOG_LEVEL=$2; LOG_LEVEL=$2;
shift 2 ;; shift 2 ;;
"--log-file") "--log-file")
# Test if file is writeable # Test if file is writeable
! test_file_perms "w" "${2}" && echo "$name: '${2}' is not writeable!" >&2 && exit 1 ! test_file_perms "w" "${2}" && echo "$name: '${2}' is not writeable!" >&2 && exit 1
_FORCED_LOG_FILE=$2 _FORCED_LOG_FILE=$2
shift 2 ;; shift 2 ;;
"-f"|"--force-run") "-f"|"--force-run")
_FORCE_RUN=true _FORCE_RUN=true
shift ;; shift ;;
"-q"|"--quiet") "-q"|"--quiet")
_QUIET_MODE=true _QUIET_MODE=true
shift ;; shift ;;
"-v"|"--verbose") "-v"|"--verbose")
! $_QUIET_MODE && _VERBOSE_MODE=true ! $_QUIET_MODE && _VERBOSE_MODE=true
shift ;; shift ;;
"-p"|"--progress") "-p"|"--progress")
! $_QUIET_MODE && _SHOW_PROGRESS=true ! $_QUIET_MODE && _SHOW_PROGRESS=true
shift ;; shift ;;
"-h"|"--help") "-h"|"--help")
print_help print_help
exit ;; exit ;;
*) *)
shift shift
break ;; break ;;
esac esac
done done
} }
############################################################################### ###############################################################################
@ -463,9 +463,9 @@ parse_cmd_args "$@"
# Check if a backup is already running # Check if a backup is already running
if [ -f /tmp/rs-backup.lock ] && ! $_FORCE_RUN; then if [ -f /tmp/rs-backup.lock ] && ! $_FORCE_RUN; then
write_log 1 "Backup lock file exists. Either a backup is already running or it didn't shut down properly last time." write_log 1 "Backup lock file exists. Either a backup is already running or it didn't shut down properly last time."
write_log 1 "If you're sure no backup is running right now, remove the lock file '/tmp/rs-backup.lock' or use the '--force-run' parameter." write_log 1 "If you're sure no backup is running right now, remove the lock file '/tmp/rs-backup.lock' or use the '--force-run' parameter."
exit 1 exit 1
fi fi
write_log 4 "No other backup running, ready to start." write_log 4 "No other backup running, ready to start."
@ -476,20 +476,20 @@ touch /tmp/rs-backup.lock
# Check if script has been invoked as root # Check if script has been invoked as root
if [ $(id -u) -eq 0 ]; then if [ $(id -u) -eq 0 ]; then
write_log 4 "Running as root, performing global system backup..." write_log 4 "Running as root, performing global system backup..."
back_up_system back_up_system
if ! $_SKIP_HOME_DIRS; then if ! $_SKIP_HOME_DIRS; then
back_up_home_dirs back_up_home_dirs
else else
write_log 3 "Skipping home directory backup as requested." write_log 3 "Skipping home directory backup as requested."
fi fi
else else
write_log 3 "Running without root privileges, only backing up user home directory..." write_log 3 "Running without root privileges, only backing up user home directory..."
if [ "${HOME}" != "" ]; then if [ "${HOME}" != "" ]; then
back_up_single_home_dir "$(realpath ${HOME})" "$(id -nu)" back_up_single_home_dir "$(realpath ${HOME})" "$(id -nu)"
else else
write_log 2 "Current user has no home directory, skipping." write_log 2 "Current user has no home directory, skipping."
fi fi
fi fi
write_log 4 "Removing lock file..." write_log 4 "Removing lock file..."
@ -498,5 +498,5 @@ rm /tmp/rs-backup.lock
write_log 4 "Done." write_log 4 "Done."
if [ $_ERROR_COUNT -gt 0 ]; then if [ $_ERROR_COUNT -gt 0 ]; then
exit 1 exit 1
fi fi

View File

@ -51,7 +51,7 @@ chmod 0644 "${HOME_DIR}/rsnapshot.conf"
mkdir -p "${HOME_DIR}/${FILES_DIR}/.sync" mkdir -p "${HOME_DIR}/${FILES_DIR}/.sync"
# Set permissions for backup directory # Set permissions for backup directory
chown -R ${USERNAME}:${GROUPNAME} "${HOME_DIR}/${FILES_DIR}" chown -R "${USERNAME}:${GROUPNAME}" "${HOME_DIR}/${FILES_DIR}"
chmod -R 0755 "${HOME_DIR}/${FILES_DIR}" chmod -R 0755 "${HOME_DIR}/${FILES_DIR}"
# If SSH key file has been specified # If SSH key file has been specified