Cleaning up a sparsebundle with a script
Posted
by
nickg
on Stack Overflow
See other posts from Stack Overflow
or by nickg
Published on 2013-11-05T15:50:29Z
Indexed on
2013/11/05
15:53 UTC
Read the original article
Hit count: 300
I'm using time machine to backup some servers to a sparse disk image bundle and I'd like to have a script to clean up the old back ups and re-size the image once space has been freed up. I'm fairly certain the data is protected because if I delete the old backups by right clicking, I have to enter a password to be able to delete them. To allow my script to be able to delete them, I've been running it as root. For some reason, it just won't run and every file it tries to delete I get
rm: /file/: Operation not permitted
Here is what I have as my script:
#!/bin/bash
for server in servername; do
/usr/bin/hdiutil attach -mountpoint /path/to/mountpoint /path/to/sparsebundle/$server.sparsebundle/;
/bin/sleep 10;
/usr/bin/find /path/to/mountpoint -type d -mtime +7 -exec /bin/rm -rf {} \;
/usr/bin/hdiutil unmount /path/to/mountpoint;
/bin/sleep 10;
/usr/bin/hdiutil compact /path/to/sparsebundle/$server.sparsebundle/;
done
exit;
One of the problems I thought was causing this was it needed to have a mountpoint specified since the default mount was to /Volumes/Time\ Machine\ Backups/ that's why I created a mountpoint. I also thought that it was trying to delete the files to quickly after mounting and it wasn't actually mounted yet, that's why I added the sleep. I've also tried using the -delete
option for find instead of -exec
, but it didn't make any difference.
Any help on this would be greatly appreciated because I'm out of ideas as to why this won't work.
© Stack Overflow or respective owner