#!/bin/bash
# /usr/local/bin/tomril.update.sh
# http://crystalfaeries.net/posix/bin/tomril.update.sh
# celeste:crystalfaery 2015-08-29 00:09:57+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 what is important to us to back-up to the SD Card.
synctxt # merge .todo lists
cd /home/www-/ || exit -1 # update the SD card
for remove in `cat .exclude.txt`
do
if [ -L "$remove" ]
then echo "ignoring target of symlink $remove"
else rm -rf "$remove"
fi
done # exclude implies delete
rsync -auvzH --delete --exclude-from=.exclude.txt \
--exclude=.du.txt --exclude=.update.sh --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 /dev/mmcblk0p1 >> .du.txt # This partition
echo "" >> .du.txt
echo " EXCLUDED:" >> .du.txt
# filter out our overhead files and weblog files
grep -v .exclude.txt /tmp/du.$$.txt | grep -v .update.sh | 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`.update.sh
syntax highlighted by Code2HTML, v. 0.9.1