For awhile I have been using a Tarsnap backup script written by Tim Bishop. It is very handy but recently I was setting up Tarsnap again on a new machine and I noticed that it is not designed to be run more frequently than daily. So I decided to take a stab at making it handle being run more often and keeping the number of daily/weekly/monthly backups that are actually desired.
Changing the delete portion to something like this should do the trick:
if [ X"$DOM" = X"$MONTHLY_DAY" ]; then
# keep monthly backups for the actual number of days even when this script is run more than once per day
#for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-monthly-$dir" $TMPFILE | sort -rn | tail +$MONTHLY`; do
for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-monthly-${dir}" ${TMPFILE} | sort -rn | cut -d '-' -f 1 | uniq | tail +${MONTHLY}`; do
for x in `grep -E "^${i}-[[:digit:]]{6}-monthly-${dir}" ${TMPFILE}`; do
echo "==> delete $x"
$TARSNAP -d -f $x
done
done
# Weekly
elif [ X"$DOW" = X"$WEEKLY_DAY" ]; then
# keep weekly backups for the actual number of days even when this script is run more than once per day
#for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-weekly-$dir" $TMPFILE | sort -rn | tail +$WEEKLY`; do
for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-weekly-${dir}" ${TMPFILE} | sort -rn | cut -d '-' -f 1 | uniq | tail +${WEEKLY}`; do
for x in `grep -E "^${i}-[[:digit:]]{6}-weekly-${dir}" ${TMPFILE}`; do
echo "==> delete $x"
$TARSNAP -d -f $x
done
done
else
#for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-daily-$dir" $TMPFILE | sort -rn | tail +$DAILY`; do
# keep daily backups for the actual number of days even when this script is run more than once per day
for i in `grep -E "^[[:digit:]]{8}-[[:digit:]]{6}-daily-${dir}" ${TMPFILE} | sort -rn | cut -d '-' -f 1 | uniq | tail +${DAILY}`; do
# delete old days
for x in `grep -E "^${i}-[[:digit:]]{6}-daily-${dir}" ${TMPFILE}`; do
echo "==> delete ${x}"
$TARSNAP -d -f ${x}
done
done
fi
I should probably just go all the way and teach it about hourly backups, but I am feeling lazy, so maybe another time.