]> arthur.barton.de Git - backup-script.git/blobdiff - bin/backup-audit
backup-audit: Exclude /proc, /sys, and /net
[backup-script.git] / bin / backup-audit
index 2a3b99736fc8214829d3024f7f5c735bd4c6f4f4..cec0145b0a20102c92165c5528e28bad0816716e 100755 (executable)
@@ -10,7 +10,7 @@
 # Please read the file COPYING, README and AUTHORS for more information.
 #
 
-NAME=`basename $0`
+NAME=$(basename "$0")
 
 VERBOSE=0
 QUIET=0
@@ -55,7 +55,7 @@ BeginDiff() {
 PipeDiff() {
        local line
        IFS=
-       while read line; do
+       while read -r line; do
                echo -e "     | $line"
        done
 }
@@ -64,6 +64,24 @@ EndDiff() {
        :
 }
 
+ListDirectory() {
+       local base_dir="$1"
+       local dir_name="$2"
+
+       local exclude
+
+       exclude='total | .$| ..$'
+       if [[ "$dir_name" == "/" ]]; then
+               exclude="$exclude"'| \.stamp$| dev$| etc$| proc$| root$| run$| sys$| tmp$'
+               exclude="$exclude"'| data$| net$| srv$'
+               exclude="$exclude"'| [[:alnum:]_-]+\.log(\.[[:alnum:]]+|)$'
+       fi
+
+       # shellcheck disable=SC2012
+       ls -al "$base_dir$dir_name" 2>/dev/null \
+               | egrep -v "($exclude)"
+}
+
 HandleSystem() {
        local fname="$1"
 
@@ -110,6 +128,7 @@ HandleSystem() {
        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
@@ -119,10 +138,12 @@ HandleSystem() {
 
        # Search previous generation without errors
        local previous_d=""
-       for d in $(ls -1dt $target/[0-9]*-[0-9]*); 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
@@ -160,13 +181,33 @@ DiffGenerations() {
                        /etc/group \
                        /etc/gshadow \
                        \
+                       /boot/grub/grub.cfg \
+                       /etc/aliases \
+                       /etc/bash.bashrc \
+                       /etc/crontab \
+                       /etc/environment \
                        /etc/fstab \
                        /etc/hostname \
                        /etc/hosts \
+                       /etc/hosts.allow \
+                       /etc/hosts.deny \
+                       /etc/inittab \
+                       /etc/ld.so.conf \
+                       /etc/login.defs \
                        /etc/machine-id \
                        /etc/modules \
                        /etc/network/interfaces \
                        /etc/networks \
+                       /etc/nsswitch.conf \
+                       /etc/profile \
+                       /etc/rc.local \
+                       /etc/resolv.conf \
+                       /etc/services \
+                       /etc/shells \
+                       /etc/ssh/sshd_config \
+                       /etc/sshd_config \
+                       /etc/sudoers \
+                       /etc/sysctl.conf \
                ; do
                        [[ -r "${gen1_d}${file}" ]] || continue
 
@@ -180,6 +221,35 @@ DiffGenerations() {
                        fi
                done
 
+               for dir in \
+                       / \
+                       /etc/cron.d/ \
+                       /etc/cron.daily/ \
+                       /etc/cron.hourly/ \
+                       /etc/cron.monthly/ \
+                       /etc/cron.weekly/ \
+                       /etc/sudoers.d/ \
+                       /var/log/dumps/ \
+               ; do
+                       [[ ! -d "${gen1_d}${dir}" ]] && continue
+                       [[ ! -d "${gen2_d}${dir}" ]] && continue
+
+                       # Make sure that this is a system root; comparing other
+                       # root folders results in misleading output ...
+                       [[ "$dir" == "/" && ! -d "${gen1_d}${dir}/etc" ]] && continue
+
+                       [[ $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
+                               BeginDiff "\"$dir\" directory"
+                               tail -n +3 "$tmp_diff" | egrep -v '^@@ ' | PipeDiff
+                               EndDiff
+                               return_code=1
+                       fi
+               done
+
                if [[ -d "${gen1_d}/var/lib/dpkg/info" && -d "${gen2_d}/var/lib/dpkg/info" ]]; then
                        [[ $VERBOSE -ne 0 ]] && echo "Checking list of installed packages ..."
                        chroot "${gen1_d}" dpkg --get-selections >"$tmp_1" || return 2
@@ -212,10 +282,10 @@ DiffGenerations() {
 }
 
 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() {
@@ -228,7 +298,7 @@ while [[ $# -gt 0 ]]; do
                shift
                [[ $# -eq 2 ]] || Usage
                MkTempFiles
-               DiffGenerations "$default_backup_type" "$1/" "$2/" "$default_files"
+               DiffGenerations "$default_backup_type" "$1" "$2" "$default_files"
                return_code=$?
                CleanUp
                exit $return_code
@@ -263,7 +333,7 @@ MkTempFiles
 for f in "${sys[@]}"; do
        [[ -r "$f" && -f "$f" ]] || continue
 
-       fname=`basename $f`
+       fname=$(basename "$f")
        case "$fname" in
                "backup-script.conf"|*.sh)
                        continue