Write sync status to HDD_LOG/log2ram.log.

- Store sync status directly in the HDD log, to make sure we know
  about it if something fails.  This won't help if the HDD_LOG
  variable is borked, but it'll help with everything else.

- Made sync a function to avoid repeating five lines three times.

- log2ram now requires (cp or rsync) and tee, mount, umount.
This commit is contained in:
Nick Daly 2016-11-30 11:24:41 -06:00
parent edd77da64e
commit 7d825982ae
1 changed files with 12 additions and 15 deletions

27
log2ram
View File

@ -2,37 +2,34 @@
HDD_LOG=/var/log.hdd/
RAM_LOG=/var/log/
LOG2RAM_LOG="${HDD_LOG}log2ram.log"
SIZE=40M
USE_RSYNC=false
sync () {
if [ "$USE_RSYNC" = true ]; then
rsync -aXWv --delete --links $HDD_LOG $RAM_LOG 2>&1 | tee -a $LOG2RAM_LOG
else
cp -rfup $HDD_LOG -T $RAM_LOG 2>&1 | tee -a $LOG2RAM_LOG
fi
}
case "$1" in
start)
[ -d $HDD_LOG ] || mkdir $HDD_LOG
mount --bind $RAM_LOG $HDD_LOG
mount --make-private $HDD_LOG
mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=$SIZE log2ram $RAM_LOG
if [ "$USE_RSYNC" = true ]; then
rsync -aXWv --delete --links $HDD_LOG $RAM_LOG
else
cp -rfup $HDD_LOG -T $RAM_LOG
fi
sync
;;
stop)
if [ "$USE_RSYNC" = true ]; then
rsync -aXWv --delete --links $RAM_LOG $HDD_LOG
else
cp -rfup $RAM_LOG -T $HDD_LOG
fi
sync
umount -l $RAM_LOG
umount -l $HDD_LOG
;;
write)
if [ "$USE_RSYNC" = true ]; then
rsync -aXWv --delete --links $RAM_LOG $HDD_LOG
else
cp -rfup $RAM_LOG -T $HDD_LOG
fi
sync
;;
esac