Reclaiming hard drive space from sparsebundle images

This week I've been dealing with some computer backup issues. I have around 7TB of disk space (not all used) which needs to be backed up. I've written some shell scripts using rsync which do the actual backing up of the files. To complicate things, most of my source files are stored in encrypted sparsebundle images on my Mac. The sparsebundle images have to be mounted (with passwords entered) before any files can be accessed. Most of my backups are also to encrypted sparsebundle images.
Sparsebundle images are set to a maximum size when you create them, but until you actually put data into the sparsebundle, it doesn't actually attempt to claim that space on the disk. This is nice and I have created several images which if they were all full, would be larger than the physical hard disk.
But one thing I didn't realize until today is that sparsebundle images do not automatically RELEASE free space when files are deleted. What happened to me today was that my backups filled up an entire disk. So I deleted some things, but the free space never showed up in Finder. I repaired the disks in Disk Utility, but still no free space.
A quick search on the internet introduced me to the "hdiutil compact" command. "hdiutil" is the command line command used to mount and unmount sparsebundle images. I was already using this command in my shell scripts to backup my data. I learned today that "hdiutil compact" will release the free space in the sparsebundles back to the hard drive as long as the entire sparsebundle band is empty. Sparsebundle disk images are made up of multiple "bands" which are small encrypted files that contain the actual data. On my setup, each band is 8.3MB, so as long as the entire 8.3MB is free, the compact command will release it.
If you want me to explain anything in more detail, let me know in the comments or email me.
