]> arthur.barton.de Git - backup-script.git/blobdiff - bin/backup-audit
backup-audit: Exclude quota status files in / directory
[backup-script.git] / bin / backup-audit
index 4f3358674f0ca5ca2dc7771909c366a3df32da8d..7ead1969283b968b5ea7b65124654d05346f204d 100755 (executable)
@@ -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-2019 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" \
@@ -76,16 +79,27 @@ 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$'
                exclude="$exclude"'| [[:alnum:]_-]+\.log(\.[[:alnum:]]+|)$'
+               exclude="$exclude"'| (aquota.user|aquota.group)$'
        fi
 
        # shellcheck disable=SC2012
-       ls -Al "$base_dir$dir_name" 2>/dev/null \
-               | egrep -v "($exclude)" | awk '!($2="")' | column -t
+       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)"
+}
+
+ListFilesRecursive() {
+       local base_dir="$1"
+       local dir_name="$2"
+
+       (
+               cd "$base_dir" || return 1
+               find ".$dir_name" -type f -o -type l | cut -d'/' -f2-
+       )
 }
 
 HandleSystem() {
@@ -137,9 +151,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
@@ -191,6 +204,7 @@ DiffGenerations() {
                        /etc/aliases \
                        /etc/bash.bashrc \
                        /etc/crontab \
+                       /etc/debian_version \
                        /etc/environment \
                        /etc/fstab \
                        /etc/hostname \
@@ -233,6 +247,7 @@ DiffGenerations() {
                        /etc/cron.hourly/ \
                        /etc/cron.monthly/ \
                        /etc/cron.weekly/ \
+                       /etc/init.d/ \
                        /etc/sudoers.d/ \
                        /var/log/dumps/ \
                ; do
@@ -248,7 +263,37 @@ DiffGenerations() {
                        ListDirectory "${gen2_d}" "${dir}" >"$tmp_2"
                        if ! diff -U 0 "$tmp_1" "$tmp_2" >"$tmp_diff"; then
                                BeginDiff "\"$dir\" directory"
-                               tail -n +3 "$tmp_diff" | egrep -v '^@@ ' | PipeDiff
+                               tail -n +3 "$tmp_diff" | grep -Ev '^@@ ' | PipeDiff
+                               EndDiff
+                               return_code=1
+                       fi
+               done
+
+               for dir in \
+                       /etc/systemd/network/ \
+                       /etc/systemd/system/ \
+                       /etc/systemd/user/ \
+                       /lib/systemd/network/ \
+                       /lib/systemd/system/ \
+                       /lib/systemd/user/ \
+                       /run/systemd/system/ \
+                       /usr/lib/systemd/network/ \
+                       /usr/lib/systemd/system/ \
+                       /usr/lib/systemd/user/ \
+               ; 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 systemd hierarchy \"$dir\" ..."
+                       ListFilesRecursive "${gen1_d}" "${dir}" >"$tmp_1"
+                       ListFilesRecursive "${gen2_d}" "${dir}" >"$tmp_2"
+                       if ! diff -U 0 "$tmp_1" "$tmp_2" >"$tmp_diff"; then
+                               BeginDiff "\"$dir\" directory"
+                               tail -n +3 "$tmp_diff" | grep -Ev '^@@ ' | PipeDiff
                                EndDiff
                                return_code=1
                        fi