Added arbitery config files snapping

master
Mateusz Chochół 8 years ago
parent 0807492c28
commit d941595fbf
  1. 30
      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

Loading…
Cancel
Save