# Please read the file COPYING, README and AUTHORS for more information.
#
-NAME=`basename $0`
+NAME=$(basename "$0")
VERBOSE=0
QUIET=0
PipeDiff() {
local line
IFS=
- while read line; do
+ while read -r line; do
echo -e " | $line"
done
}
echo "Found latest generation in \"$latest_d\"."
declare -i code=-1
+ # shellcheck source=/dev/null
source "$latest_d/.stamp"
if [[ $code -ne 0 && $code -ne 24 ]]; then
# Search previous generation without errors
local previous_d=""
- for d in $(ls -1dt $target/[0-9]*-[0-9]* 2>/dev/null); do
+ # shellcheck disable=SC2045
+ for d in $(ls -1dt "$target/"[0-9]*-[0-9]* 2>/dev/null); do
[[ -d "$d" && -r "$d/.stamp" ]] || return 0
declare -i code=-1
+ # shellcheck source=/dev/null
source "$d/.stamp"
if [[ $code -eq 0 || $code -eq 24 ]]; then
}
MkTempFiles() {
- tmp_1=$(mktemp /tmp/$NAME.XXXXXX) || exit 1
- tmp_2=$(mktemp /tmp/$NAME.XXXXXX) || exit 1
- tmp_diff=$(mktemp /tmp/$NAME.XXXXXX) || exit 1
- tmp_out=$(mktemp /tmp/$NAME.XXXXXX) || exit 1
+ tmp_1=$(mktemp "/tmp/$NAME.XXXXXX") || exit 1
+ tmp_2=$(mktemp "/tmp/$NAME.XXXXXX") || exit 1
+ tmp_diff=$(mktemp "/tmp/$NAME.XXXXXX") || exit 1
+ tmp_out=$(mktemp "/tmp/$NAME.XXXXXX") || exit 1
}
CleanUp() {
for f in "${sys[@]}"; do
[[ -r "$f" && -f "$f" ]] || continue
- fname=`basename $f`
+ fname=$(basename "$f")
case "$fname" in
"backup-script.conf"|*.sh)
continue
echo
echo "When no <system> is given, all defined systems are used."
echo
+ # shellcheck disable=SC2086
echo -e $config_info
echo
exit 2
case "$fs" in
"btrfs")
# Search directory of last generation, if any
+ # shellcheck disable=SC2012
last=$(ls -1d "$sys_target"/[0-9]* 2>/dev/null | sort -r | head -n1)
if [ -n "$last" ]; then
if [ ! -d "$last" ]; then
$SHELL -c "$cmd"; ret=$?
end_t=$(date "+%s")
- echo "code=$ret" >"$stamp_file"
- echo "start_t=$start_t" >>"$stamp_file"
- echo "end_t=$end_t" >>"$stamp_file"
- echo "cmd='$cmd'" >>"$stamp_file"
- echo "backup_host='`hostname -f`'" >>"$stamp_file"
- echo "backup_user='`id -un`'" >>"$stamp_file"
+ {
+ echo "code=$ret"
+ echo "start_t=$start_t"
+ echo "end_t=$end_t"
+ echo "cmd='$cmd'"
+ echo "backup_host='$(hostname -f)'"
+ echo "backup_user='$(id -un)'"
+ } >"$stamp_file"
else
echo " *** Trial run, not executing save command!"
ret=0
fi
# Clean up old generations
declare -i gen_count=$generations+2
+ # shellcheck disable=SC2012
to_delete=$(ls -1t "$sys_root" 2>/dev/null | tail -n+$gen_count | sort)
if [[ -n "$to_delete" && $ok -eq 1 ]]; then
[ "$DRYRUN" -eq 0 ] \
fi
last=$(stat "$dir/.stamp" 2>/dev/null | grep "^Modify: " \
| cut -d':' -f2- | cut -d. -f1)
+ # shellcheck disable=SC2086
echo "Removing backup from" $last "..."
if [ "$DRYRUN" -eq 0 ]; then
DeleteSubvolume "$dir"
if [ "$DRYRUN" -eq 0 ]; then
paths=""
paths_zfs=""
+ # shellcheck disable=SC2086
for dest in $(echo $destinations | sed -e 's/ /\n/g' | sort | uniq); do
fs=$(GetFS "$dest")
case $fs in
esac
done
if [ -n "$paths" ]; then
+ # shellcheck disable=SC2086
df -h $paths
echo
fi
if [ -n "$paths_zfs" ]; then
+ # shellcheck disable=SC2086
zfs list $paths_zfs
echo
fi
NAME="backup-script"
DELIMITER="- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
-HOST=`hostname -f`
+HOST=$(hostname -f)
LOGFILE="/var/log/$NAME.log"
SUBJECT="$NAME results"
-TMP=`mktemp /tmp/$NAME.XXXXXXXX` || exit 1
+TMP=$(mktemp /tmp/$NAME.XXXXXXXX) || exit 1
PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
export PATH
echo "$NAME Report"
echo
-echo " - Host: `hostname -f`"
-echo " - User: `id -un`"
+echo " - Host: $(hostname -f)"
+echo " - User: $(id -un)"
echo
echo "Command:"
echo "$0" "$@"
SUBJECT="$SUBJECT - with ERRORS!"
esac
-cat "$TMP" | mail -s "$HOST: $SUBJECT" "$MAILTO"
+mail -s "$HOST: $SUBJECT" "$MAILTO" <"$TMP"
rm -f "$TMP"
exit $r
# Please read the file COPYING, README and AUTHORS for more information.
#
-NAME=`basename $0`
+NAME=$(basename "$0")
PIDFILE="/var/run/backup-script.pid"
QUICK=0
ONLY_ERRORS=0
# $2: padding
if [ "$QUICK" = "0" ]; then
- size=`du -Hhs "$1" | cut -f1`
+ size=$(du -Hhs "$1" | cut -f1)
+ # shellcheck disable=SC2086
echo "$2 - Size:" $size
fi
}
duration_t=$end_t-$start_t
else
if [ "$(uname)" = "Linux" ]; then
- end=`LC_ALL=C stat "$1" | grep "^Modify: " \
- | cut -d':' -f2- | cut -d. -f1`
+ end=$(LC_ALL=C stat "$1" | grep "^Modify: " \
+ | cut -d':' -f2- | cut -d. -f1)
else
- end=`LC_ALL=C stat -f "%Sc" "$1"`
+ end=$(LC_ALL=C stat -f "%Sc" "$1")
fi
fi
+ # shellcheck disable=SC2086
[ -n "$start" ] && echo "$2 - Start date:" $start
+ # shellcheck disable=SC2086
[ -n "$end" ] && echo "$2 - End date:" $end
if [ $duration_t -gt -1 ]; then
declare -i s=$duration_t
if [ $s -ge 60 ]; then
- declare -i m=$(($s/60))
- declare -i s=$(($s%60))
+ declare -i m=$((s / 60))
+ declare -i s=$((s % 60))
if [ $m -ge 60 ]; then
- declare -i h=$(($m/60))
- declare -i m=$(($m%60))
+ declare -i h=$((m / 60))
+ declare -i m=$((m % 60))
if [ $h -ge 24 ]; then
- declare -i d=$(($h/24))
- declare -i h=$(($h%24))
+ declare -i d=$((h / 24))
+ declare -i h=$((h % 24))
duration="${d}d${h}h${m}m${s}s"
else
duration="${h}h${m}m${s}s"
for f in "${sys[@]}"; do
[[ -r "$f" && -f "$f" ]] || continue
- fname=`basename $f`
+ fname=$(basename "$f")
case "$fname" in
"backup-script.conf"|*.sh)
continue