Current location

narf Source control manager Git

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Mehani <shtrom@ssji.net>2018-04-22 13:23:27 +0200
committerOlivier Mehani <shtrom@ssji.net>2018-04-22 13:25:04 +0200
commit807988a8e4d802be95aec0dfe61a97a9a3082dc8 (patch)
treed9b6a829a452d69eed4ac340fb53af0aee63962c
parent3032aa845ee039b566a6b5e885dce1e5e0f2696d (diff)
Embetter titanium cleanup
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
-rwxr-xr-xopenbsd/titanium-cleanup.sh21
1 files changed, 16 insertions, 5 deletions
diff --git a/openbsd/titanium-cleanup.sh b/openbsd/titanium-cleanup.sh
index 108a51b..77d2a08 100755
--- a/openbsd/titanium-cleanup.sh
+++ b/openbsd/titanium-cleanup.sh
@@ -1,13 +1,24 @@
#!/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=.
+BACKUPPATH=${1}
-PACKAGES=$(ls "${BACKUPPATH}" | sed s/-.*// | sort -u )
+cd ${BACKUPPATH}
+
+PACKAGES=$(ls | sed s/-.*// | sort -u )
for PKG in ${PACKAGES}; do
- ls -1tr ${PKG}-*.properties | head -n -1 | xargs rm
- ls -1tr ${PKG}-*.tar.bz2 | head -n -1 | xargs rm
- ls -1tr ${PKG}-*.apk.* | head -n -1 | xargs rm
+ FILES=$(ls -1tr ${PKG}-*.properties 2>/dev/null | sed 1d)
+ FILES=$(ls -1tr ${PKG}-*.tar.bz2 2>/dev/null | sed 1d)
+ FILES=$(ls -1tr ${PKG}-*.apk.* 2>/dev/null | sed 1d)
+ test -n "${FILES}" && rm ${FILES}
done