Shirt Pocket Discussions

Shirt Pocket Discussions (
-   General (
-   -   Sparse image grows beyond actual data? (

jamart 07-29-2005 05:09 PM

Sparse image grows beyond actual data?
I have been using SuperDuper to backup to sparse images created with Disk Utility to potentially expand to the full size of the original volume. For my needs, I like this approach better than Retrospect.

I recently noticed that the sparse image continually expands with each backup to far beyond the actual data written into it. Aparently the new/changed files is written and then the old files are deleted but the disk image does not release the empty space.

Is there a way to retrieve the disk space being retained without data by the sparseimage?



dnanian 07-29-2005 05:15 PM

You can potentially recover unused space in the image using hdiutil and the "compact" option. You have to do this in the Terminal.

The syntax would be:

hdiutil compact image-file

So, if your image is called "My Happy Image.sparseimage" and it's stored on your desktop, you'd use:

hdiutil compact ~/Desktop/My\ Happy\ Image.sparseimage

(the backslashes escape the spaces, the "~" means "My Home Folder").

You can also just type:

hdiutil compact

(include a space at the end)

and then drag the image file into the Terminal -- OSX will automatically put the path in place for you.

jamart 07-29-2005 05:46 PM

Thanks Dave,

That worked very well.

dnanian 07-29-2005 08:17 PM

Great: glad to hear it!

Bartmart 09-27-2005 02:22 PM

Sparse problem too
I'm having the same troubles with sparse image sizes and after following your instructions to compact I get an error in Terminal saying, "hdiutil:compact failed - internal error".

I'm not a wizbang with Terminal. Any ideas?



dnanian 09-27-2005 02:27 PM

Sounds like it doesn't want to compact, Wayne... the image frameworks can be buggy, unfortunately, and you might have hit one of the situations where those bugs are exposed.

Are you certain you gave it a good "path" when you specified the location of the image?

Bartmart 09-27-2005 03:35 PM

Found a script
Hi Dave,

Found an apple script at: <>.

Seems to work if I drag the image to the app as stated.



dnanian 09-27-2005 03:57 PM

Ah, good. So the path must have been mis-specified. Glad you've got it working.

edoates 10-08-2005 04:44 PM

Sparse image compacting automatically
I got tired of checking the size of my sparse images and manually compacting them with hdiutil. So, I added the script fragment below to the end of the "daily backup applescript" which I had already modified for my specific volumes:

tell application "Finder"
eject disk "Music Backups"
end tell
display dialog "Awaiting dismount of Music Backups" buttons {"OK"} giving up after 5 default button 1
-- compact the sparse image to prevent unregulated growth
do shell script "hdiutil compact " & "\"/Volumes/Eds Office Backups/Music Backups.sparseimage\""
display dialog "Music Backup Complete" buttons {"OK"} giving up after 30 default button 1

The "activate" verbs cause the script to become the top application so the dialogs show up (for testing, mostly); the dialogs are all for information and time out. I wait 5 seconds for the dismount to occur: always enough time unless the volume cannot be dismounted for some reason. hdiutil will not compact a mounted sparse image.

Hope you find this useful.


dnanian 10-08-2005 04:49 PM

Nice work, Ed. Thanks!

All times are GMT -4. The time now is 12:39 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2022, vBulletin Solutions, Inc.