Skip to content

Instantly share code, notes, and snippets.

@simbalinux
Last active July 12, 2018 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simbalinux/4174a77335c435dc66ed9ddf9cbf4410 to your computer and use it in GitHub Desktop.
Save simbalinux/4174a77335c435dc66ed9ddf9cbf4410 to your computer and use it in GitHub Desktop.
CGI program written in shell to evaluate filesystem
#!/usr/bin/env bash
shopt -s nullglob
exec > /path/to/logfile
# Variables
sql_path="/path/to/backup"
data_path="/path/to/backup"
days=7
testvalue=1
# Arrays
mapfile -t sql < <(find "$sql_path" -type f -mtime -"$days")
mapfile -t data < <(find "$data_path" -type f -mtime -"$days")
# Job start email notifier optional invoke this if your job will take a long time to run.
#echo Starting Backup Eval | mailx -r "$sender" -s "$subject" "$recipient"
# create new array via matches
inarray()
{
local n=$1 h
shift
for h; do [[ $n = "$h" ]] && newarray+=("$n"); done;
}
report_builder ()
{
arr=("$@")
printf "<br />"
#echo "<center><b><font size="16px;">Summary Backup Infrastructure Report for the past "$days" days</font></b></center>"
echo "<center style=\"font-size:16px;\"><b>Summary Backup Infrastructure Report for the past "$days" days</b></center>"
printf "<br /><center>Week of $(date)</center><br />"
printf "<br />"
printf "<br />"
printf "<br /><b>BACKUPS directory to be verified: </b>"$1"<br /><br />"
echo "<b>Instances backed up:</b> "${#arr[@]}"<br />"
echo "<b>Smallest backup:</b> $(find "$1" -type f -mtime -"$days" | xargs du -h | sort -h | head -n 1)<br />"
echo "<b>Largest backup:</b> $(find "$1" -type f -mtime -"$days" | xargs du -h | sort -h | tail -n 1)<br />"
echo "<b>Total size of Backups:</b> $(du -ch "$1" |grep total)"
# get all 0 byte files
for item in "${arr[@]}"; do
filesize=$(stat -c%s "$item" )
if (( "$filesize" < "$testvalue" )); then
inarray "$item" "${arr[@]}"
fi
done
echo "<br /><b>Empty Erroneous Backups During the Week: </b>"
# print 0 byte files
for size in "${newarray[@]}"; do
ls -al "$size"
done
(( ${#newarray[@]} )) || echo "No 0 byte backups have been logged"
printf "<br /><br />"
printf "<br />"
echo "<b>Full list of Backed up Instances for</b> "$(date)"<br />"
printf "<br /><br />"
find $dir_name "$1" -type f -mtime -"$days" -printf "%M %n %u %g %s %Tb %Td %Tk:%TM %p<br />"
}
#functions will be called twice 1 for each directory evaluation
report_builder "$sql_path" "${sql[@]}"
report_builder "$data_path" "${data[@]}"
(echo "Content-Type: text/html"; curl localhost/cgi-bin/report.cgi) | /usr/sbin/sendmail user@domain.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment