X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=bin%2Fbackup-audit;h=4371bc7ae7ede3e3abb354720edf1684c3521f9e;hb=ee7dad6ebc7d49363c0dfeb3059fb7ec78f2e08d;hp=cec0145b0a20102c92165c5528e28bad0816716e;hpb=1f1ac2b2ee66b81a086c3153fb8c001bc1ef0a12;p=backup-script.git diff --git a/bin/backup-audit b/bin/backup-audit index cec0145..4371bc7 100755 --- a/bin/backup-audit +++ b/bin/backup-audit @@ -1,7 +1,7 @@ #!/bin/bash # # backup-script system for cloning systems using rsync -# Copyright (c)2008-2016 Alexander Barton, alex@barton.de +# Copyright (c)2008-2018 Alexander Barton, alex@barton.de # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,6 +27,9 @@ default_files="running-config" default_generations=0 default_target="/var/backups" +# Set shell options. +shopt -s nullglob + # Search configuration file (last one is used as default!) for conf in \ "/usr/local/etc/backup-script.conf" \ @@ -42,9 +45,15 @@ for conf in \ done Usage() { - echo "Usage: $NAME [-q|--quiet] [-v|--verbose] [ [ [...]]]" + echo "Usage: $NAME [-q|--quiet] [-v|--verbose] [ [ [...]]]" echo " $NAME <-d|--dirs> " echo + echo " -d, --dirs Compare two backup directories (not jobs)." + echo " -q, --quiet Quite mode, only list jobs with changes or errors." + echo " -v, --verbose Verbose mode, show all checks that are run." + echo + echo "When no is given, all defined jobs are checked." + echo exit 2 } @@ -70,7 +79,7 @@ ListDirectory() { local exclude - exclude='total | .$| ..$' + exclude=' \.$' if [[ "$dir_name" == "/" ]]; then exclude="$exclude"'| \.stamp$| dev$| etc$| proc$| root$| run$| sys$| tmp$' exclude="$exclude"'| data$| net$| srv$' @@ -78,8 +87,8 @@ ListDirectory() { fi # shellcheck disable=SC2012 - ls -al "$base_dir$dir_name" 2>/dev/null \ - | egrep -v "($exclude)" + find "$base_dir$dir_name". -maxdepth 1 -printf '%M %10u:%-10g %t %12s %f\n' 2>/dev/null \ + | LC_ALL=C sort -k 9 | grep -Ev "($exclude)" } HandleSystem() { @@ -131,9 +140,8 @@ HandleSystem() { # shellcheck source=/dev/null source "$latest_d/.stamp" - if [[ $code -ne 0 && $code -ne 24 ]]; then - echo "Last backup generation has errors, skipping system!" - echo; return 1 + if [[ $code -ne 0 ]]; then + echo "Warning: Last backup generation had errors, code $code!" fi # Search previous generation without errors @@ -185,6 +193,7 @@ DiffGenerations() { /etc/aliases \ /etc/bash.bashrc \ /etc/crontab \ + /etc/debian_version \ /etc/environment \ /etc/fstab \ /etc/hostname \ @@ -212,8 +221,7 @@ DiffGenerations() { [[ -r "${gen1_d}${file}" ]] || continue [[ $VERBOSE -ne 0 ]] && echo "Checking \"$file\" ..." - diff -U 3 "${gen1_d}${file}" "${gen2_d}${file}" >"$tmp_diff" - if [[ $? -ne 0 ]]; then + if ! diff -U 3 "${gen1_d}${file}" "${gen2_d}${file}" >"$tmp_diff"; then BeginDiff "\"$file\"" tail -n +3 "$tmp_diff" | PipeDiff EndDiff @@ -228,7 +236,15 @@ DiffGenerations() { /etc/cron.hourly/ \ /etc/cron.monthly/ \ /etc/cron.weekly/ \ + /etc/init.d/ \ /etc/sudoers.d/ \ + /etc/systemd/network/ \ + /etc/systemd/system/ \ + /etc/systemd/user/ \ + /lib/systemd/network/ \ + /lib/systemd/system/ \ + /usr/lib/systemd/network/ \ + /usr/lib/systemd/user/ \ /var/log/dumps/ \ ; do [[ ! -d "${gen1_d}${dir}" ]] && continue @@ -241,8 +257,7 @@ DiffGenerations() { [[ $VERBOSE -ne 0 ]] && echo "Checking \"$dir\" ..." ListDirectory "${gen1_d}" "${dir}" >"$tmp_1" ListDirectory "${gen2_d}" "${dir}" >"$tmp_2" - diff -U 0 "$tmp_1" "$tmp_2" >"$tmp_diff" - if [[ $? -ne 0 ]]; then + if ! diff -U 0 "$tmp_1" "$tmp_2" >"$tmp_diff"; then BeginDiff "\"$dir\" directory" tail -n +3 "$tmp_diff" | egrep -v '^@@ ' | PipeDiff EndDiff @@ -254,8 +269,7 @@ DiffGenerations() { [[ $VERBOSE -ne 0 ]] && echo "Checking list of installed packages ..." chroot "${gen1_d}" dpkg --get-selections >"$tmp_1" || return 2 chroot "${gen2_d}" dpkg --get-selections >"$tmp_2" || return 2 - diff -U 0 "$tmp_1" "$tmp_2" >"$tmp_diff" - if [[ $? -ne 0 ]]; then + if ! diff -U 0 "$tmp_1" "$tmp_2" >"$tmp_diff"; then BeginDiff "list of installed packages" tail -n +3 "$tmp_diff" | grep -v '^@@ ' | PipeDiff EndDiff @@ -266,8 +280,7 @@ DiffGenerations() { # scp Backup type file=$(basename "$files") [[ $VERBOSE -ne 0 ]] && echo "Checking \"$file\" ..." - diff -U 3 "${gen1_d}/${file}" "${gen2_d}/${file}" >"$tmp_diff" - if [[ $? -ne 0 ]]; then + if ! diff -U 3 "${gen1_d}/${file}" "${gen2_d}/${file}" >"$tmp_diff"; then BeginDiff "\"$file\"" tail -n +3 "$tmp_diff" | PipeDiff EndDiff @@ -340,8 +353,8 @@ for f in "${sys[@]}"; do ;; esac - HandleSystem "$fname" >"$tmp_out" 2>&1 - [[ $QUIET -eq 0 || $? -ne 0 ]] && cat "$tmp_out" + HandleSystem "$fname" >"$tmp_out" 2>&1; result=$? + [[ $QUIET -eq 0 || $result -ne 0 ]] && cat "$tmp_out" done CleanUp