#!/bin/bash
#                      /usr/local/bin/muse.update.sh
# http://crystalfaeries.net/posix/bin/muse.update.sh
# celeste:crystalfaery 2015-05-10 18:41:34+00:00
# This script lives at the top level of an SD Card, and is
# manually executed to update the SD Card as a (partial)
# backup of website contents (from /home/www to /home/www-).
# At the same level the file .exclude.txt controls NON-copying.
# At the end of the update we generate a report in .du.txt
# showing us disk usage of what was or was NOT backed-up,
# in order to help us manually update the .exclude.txt file
# to optimize the important subset to back-up to the SD Card.
# This is invoked after mounting /home/www-, as /home/www-/.update.sh
# Upon completion of execution one can then unmount /home/www- again.

cd /home/www- || exit -1					# update the SD card
rm -rf					    `cat .exclude.txt`	# exclude implies delete
rsync -auvzH --delete		  --exclude-from=.exclude.txt	\
--exclude=.update.sh --exclude=.du.txt --exclude=.exclude.txt	/home/www/{.??,}*	.

# calculate disk usage report
cp /dev/null						   /tmp/du.$$.txt
for d in `cat .exclude.txt`
do
	du -s /home/www/$d | sed 's/\/home\/www\///g'	>> /tmp/du.$$.txt
done
df --full | head -n 1		> .du.txt	# Captions
df --full | grep /home/www-    >> .du.txt	# This partition
echo "" >> .du.txt
echo "	EXCLUDED:" >> .du.txt
# filter out our overhead files and weblog files
grep -v .update.sh /tmp/du.$$.txt | grep -v .du.txt | grep -v .exclude.txt | grep -v webalizer | sort -rn >> .du.txt
echo "" >> .du.txt
echo "	INCLUDED:" >> .du.txt
/usr/local/bin/dudir>>.du.txt

# manually review our choice of exclusions
vi .du.txt .exclude.txt .update.sh

# copy from the SD card to local hard disk to allow copying to other SD cards
rsync -auvzH .du.txt		 ~/txt/`hostname`.www-.du.txt
rsync -auvzH .exclude.txt	 ~/txt/`hostname`.www-.exclude.txt
rsync -auvzH .update.sh	/usr/local/bin/`hostname`.www-.update.sh


syntax highlighted by Code2HTML, v. 0.9.1