From d941595fbf037a53624ca9901c39b3a62caccaf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Choch=C3=B3=C5=82?= Date: Thu, 19 Oct 2017 17:15:11 +0200 Subject: [PATCH] Added arbitery config files snapping --- statesnap.sh | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/statesnap.sh b/statesnap.sh index 811c44d..a961a71 100755 --- a/statesnap.sh +++ b/statesnap.sh @@ -1,8 +1,18 @@ #!/bin/bash -# CONFIG +################ +## CONFIG ## +################ + +# Folder to save snaps in SNAP_FOLDER=~/server_states +# Array with files to snapshot +declare -a CFGBKP=( + "/etc/motd" + "/etc/hosts" +) + # Bash color definitions GREEN='\033[00;92m' BLUE='\033[00;94m' @@ -53,6 +63,12 @@ function makeSnap { /sbin/iptables-save > $FOLDER/iptables-save.out mount > $FOLDER/mount.out routingTable > $FOLDER/routing.out + for i in "${CFGBKP[@]}" + do + DIR=$(dirname "${i}") + mkdir -p "$FOLDER/cfg$DIR" + cp "$i" "$FOLDER/cfg$i" + done msg "Written state snapshot to $FOLDER" } @@ -65,6 +81,10 @@ function compare { echo -e "$GREEN\nFirewall rules diff$RST"; HL; firewallRules | diff - $FOLDER/iptables.out | colorDiff echo -e "$GREEN\nMounts diff$RST"; HL; mount | diff - $FOLDER/mount.out | colorDiff echo -e "$GREEN\nRouting table diff$RST"; HL; routingTable | diff - $FOLDER/routing.out | colorDiff + for i in "${CFGBKP[@]}" + do + echo -e "$GREEN\n$i config diff$RST"; HL; diff "$i" "$FOLDER/cfg$i" | colorDiff + done } # Checking if root privileges @@ -80,7 +100,8 @@ function printHelp { echo -e "State Snap 0.3"; HL echo -e "Use: $0 [PARAMETRS]...\n" printf " $GREEN%-6s$RST %s\n" "snap" "- Make server status snapshot" - printf " $GREEN%-6s$RST %s\n\n" "diff" "- Make a diff comparison against latest snapshot" + printf " $GREEN%-6s$RST %s\n" "diff" "- Make a diff comparison against latest snapshot" + printf " $GREEN%-6s$RST %s\n\n" "clear" "- Delete all previous snapshots" exit 0; } @@ -99,9 +120,10 @@ case $1 in nonRootExit makeSnap ;; + clear) + rm -r $SNAP_FOLDER/* + ;; *) msg "Unrecognised command. Run \"$0 help\" to view help." ;; esac - -