#!/system/bin/sh
#
# keep only the last backup in /drd-data/backup/ directory, if more than one is present

last_backup="$(ls -1 /drd-data/backup/*.zip 2> /dev/null | busybox tail -1)"
if [ -z "$last_backup" ] ; then
	exit 0
fi

for backup in /drd-data/backup/*.zip
do
	if [ ! -f "$backup" ] ; then
		continue
	fi
	if [ "$backup" == "$last_backup" ] ; then
		continue
	fi
	rm -f "$backup"
done

exit 0

