Friday, 25 July 2014

Reclaim free space from Time Machine sparsebundle

You msut run these commands as root:
sudo su - 
Make sure the mount point exists:
mkdir -p /Volumes/TM
Then mount the afp share:
mount_afp 'afp://user:password@afp_server_address/share_name' /Volumes/TM
Now use hdiutil to reclaim the available free space:
hdiutil compact /Volumes/TM/ComputerName.sparsebundle/
unmont the share:
umount /Volumes/TM/
If you get an error message saying:
hdiutil: compact failed - Resource temporarily unavailable
You must make sure you don't have the afp share mounted elsewhere, you can check your mounts with:
df -h
If the output contains a line with your afp server's address or with the string "Time Machine" you have to unmount them.

The following script will do all that for you:
for v in $(df -h | grep -E "$SRV|Time\sMachine"  | cut -d"%" -f3 |  sed -e "s/ *\//\//"); do
    umount "$v"
mkdir -p /Volumes/TM
mount_afp "afp://user:password@$SRV/share" /Volumes/TM
hdiutil compact "/Volumes/TM/$(scutil --get ComputerName).sparsebundle"
umount /Volumes/TM/

Possibly Related Posts

No comments:

Post a Comment