Skip to content

Instantly share code, notes, and snippets.

@auipga
Created January 11, 2017 14:37
Show Gist options
  • Save auipga/97603ecdc8e0554ac7d3e49f7e8714ef to your computer and use it in GitHub Desktop.
Save auipga/97603ecdc8e0554ac7d3e49f7e8714ef to your computer and use it in GitHub Desktop.
This script helps you to (re)move old TitaniumBackup files when you backup its folder using btsync/Bittorrent Sync/rslsync/Resilio Sync. It keeps the latest 1 backup, older backups will be moved somewhere else.
#!/bin/bash
# remove old backups keeping only the latest one
# run this script only in your TitaniumBackup folder !!!
# create this folder first!
target=old
# pipe|separated|list
exclude="this.is.an.example.org.mozilla.firefox"
# | get app IDs
apps=$(ls *.* | cut -d'-' -f1 | uniq | egrep -v $exclude)
cnt_apps=$(ls *.* | cut -d'-' -f1 | uniq | egrep -v $exclude | wc -l)
cnt_mv_apps=0
cnt_mv_tar_prop=0
cnt_mv_apk=0
echo Found $cnt_apps apps
for app in $apps; do
did_sth=0
# app-data (tar + properties)
# | remove app ID | remove extension | group by | remove last / latest
for date in $(ls ${app}-*.tar ${app}-*.properties 2> /dev/null | cut -d'-' -f2- | cut -d'.' -f1 | uniq | sed \$d); do
mv $app-$date* ${target}/
((cnt_mv_tar_prop++))
echo -n .
did_sth=1
done
# apk
for apk in $(ls -t ${app}-*.apk 2> /dev/null | sed \$d); do
mv $apk ${target}/
((cnt_mv_apk++))
echo -n .
did_sth=1
done
if [ $did_sth == 1 ]; then
((cnt_mv_apps++))
fi
done
echo
echo Moved backups of $cnt_mv_apps apps \(${cnt_mv_tar_prop}x data, ${cnt_mv_apk}x apk\)
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment