#!/bin/sh # A quick script to delete all but the most recent backup for each app # from Titanium Backup # # usage: # # sudo crontab -e -u www # # #minute hour mday month wday command # 46 4 * * * /operator/scripts/openbsd/titanium-cleanup.sh /srv/www/sites/narf.ssji.net/cloud/data/shtrom/files/Backups/snibbley/TitaniumBackup # 16 4 * * * /operator/scripts/openbsd/titanium-cleanup.sh /srv/www/sites/narf.ssji.net/cloud/data/jenny/files/Backups/BeanChicken BACKUPPATH=${1} cd ${BACKUPPATH} PACKAGES=$(ls *.apk.*| sed s/-.*// | sort -u ) COUNT=0 for PKG in ${PACKAGES}; do FILES=$(ls -1t ${PKG}-*.properties 2>/dev/null | sed 1d) FILES="${FILES:+${FILES} }$(ls -1t ${PKG}-*.tar.* 2>/dev/null | sed 1d)" FILES="${FILES:+${FILES} }$(ls -1t ${PKG}-*.apk.* 2>/dev/null | sed 1d)" test -n "${FILES}" && rm ${FILES} COUNT=$((COUNT + $(echo ${FILES} | wc -w))) done test ${COUNT} -gt 0 && echo "Cleared ${COUNT} files from ${BACKUPPATH}"