Posted by: untoro | June 7, 2011

How to limit space used by Time Machine

Having an external HD gives me a chance to use Time Machine to backup all my data.
.
Even though the initial process (first backup) is very slow, I am so impressed to see Time Machine in action. Now I can easily check how my Mac looks like, let’s say for yesterday’s date at particular hour. Just like its name, Time Machine.
.

.
At particular hour you said? Yes, by default Time Machine will create:

  • Hourly backups for the past 24 hours
  • Daily backups for the past month
  • Weekly backups for all previous months
.
However, there is one important information in the Time Machine Preferences window:
The oldest backups are deleted when your disk becomes full

.


.
What???? I did not buy this HD only to store Time Machine backups! Why there is no setting to limit the space used by Time Machine???
If you use external HD, I believe you can prepare separate partition with limited space for Time Machine. But, here I am not sure on how to do that in NAS (I am using MyBook Live).
.
After a whole day Googling, trial & error, and Googling, and trial & error (you can repeat this 5x), I managed to set limit on the image size used by Time Machine.
.
Before you go further on how to do this, all the steps were done in Mac OS X 10.6.7 and I am using MyBook Live 2TB for my NAS.

.

Here are the steps:

  1. First, switch off your time machine. You can do this from the Time Machines Preferences window. Just to be safe, I also set the Disk to None by clicking “Select Disks” and choose “None”
    .
  2. Go into Terminal and use hdiutil to resize sparsebundle used by Time Machine.
    .

    
    
    hdiutil resize -size 500g -shrinkonly /Volumes/TimeMachine/PC-benk2.sparsebundle/

    .
    On the example above, the maximum size of the sparsebundle image is 500GB. However, the exact size will be 1024*1024*1024*500 = 536.87GB.
    .
    You will need to change the path and name for the sparsebundle accordingly.

    TIPS:
    - You may need to use sudo to execute hdiutil.
    - If you got “hdiutil: resize failed – error -5341” as what I got at first time, try to reduce the size in several steps.
    In my case, first I reduce the size to 1t (1 Terabyte) and to 500g subsequently.
    .

  3. By default, Time Machine will again resizing the image up to the max when the backup is running.
    To avoid this you need to lock the Info.* files in sparsebundle by using SetFile from Terminal.
    You can get SetFile by installing Developer Tools (Xcode.mpkg) from Installation DVD.
    .

    
    
    SetFile -a L /Volumes/TimeMachine/PC-benk2.sparsebundle/Info.*

    .

  4. Now you can choose set the disk back from the Time Machine Preferences window and switch ON.From time machine preferences, the available space will still show the maximum size of your HD.
    .
  5. Open the Console from Application\Utilities to check the log and run the backup. Here in my system, I am getting below in the log:
    .

    
    
    6/7/11 12:50:47 PM com.apple.backupd[13149] Starting standard backup 6/7/11 12:50:47 PM com.apple.backupd[13149] Network destination already mounted at: /Volumes/TimeMachine 6/7/11 12:50:47 PM com.apple.backupd[13149] Warning: Destination /Volumes/TimeMachine does not support TM Lock Stealing 6/7/11 12:50:47 PM com.apple.backupd[13149] Warning: Destination /Volumes/TimeMachine does not support Server Reply Cache 6/7/11 12:50:48 PM com.apple.backupd[13149] Resizing backup disk image from 500.0 GB to 1851.3 GB 6/7/11 12:50:55 PM com.apple.backupd[13149] Could not resize backup disk image (DIHLResizeImage returned 30) 6/7/11 12:50:56 PM com.apple.backupd[13149] QUICKCHECK ONLY; FILESYSTEM CLEAN 6/7/11 12:50:59 PM com.apple.backupd[13149] Disk image /Volumes/TimeMachine/PC-benk2.sparsebundle mounted at: /Volumes/Time Machine Backups 6/7/11 12:50:59 PM com.apple.backupd[13149] Backing up to: /Volumes/Time Machine Backups/Backups.backupdb 6/7/11 12:51:01 PM com.apple.backupd[13149] No pre-backup thinning needed: 1.01 GB requested (including padding), 259.52 GB available 6/7/11 12:51:11 PM com.apple.backupd[13149] Copied 627 files (2.2 MB) from volume Macintosh HD. 6/7/11 12:51:12 PM com.apple.backupd[13149] Starting post-backup thinning 6/7/11 12:51:14 PM com.apple.backupd[13149] Deleted backup /Volumes/Time Machine Backups/Backups.backupdb/PC-benk2/2011-06-06-124852: 259.52 GB now available 6/7/11 12:51:16 PM com.apple.backupd[13149] Deleted backup /Volumes/Time Machine Backups/Backups.backupdb/PC-benk2/2011-06-06-114856: 259.53 GB now available 6/7/11 12:51:20 PM com.apple.backupd[13149] Deleted backup /Volumes/Time Machine Backups/Backups.backupdb/PC-benk2/2011-06-06-104854: 259.54 GB now available 6/7/11 12:51:20 PM com.apple.backupd[13149] Post-back up thinning complete: 3 expired backups removed 6/7/11 12:51:20 PM com.apple.backupd[13149] Backup completed successfully.

    .
    As you can see, Time Machine is unable to resize the image size :)
    .

  6. Check the Time Machine volume, and it shows the correct size.
    .

    .

.
Just to ensure everything works fine, I also restart my Mac and reboot my NAS and recheck the log when the backup run. So far until now it is still working fine.
.
Please feels free to comment.
I am not an expert on this, so please let me know in case the steps might harm my system.

Advertisement

Responses

  1. it’s generally a bad idea to alter a backup system’s data store behind its back. you’re asking for trouble.

    you’re much better off partitioning the disk of the NAS so your sparsebundle is limited to that. and then you should file a bug with apple to request this functionality.

  2. Hi,

    I tried to do what you suggest here but I always get the error Message:

    hdiutil: resize: only a single file can be specified
    Usage: hdiutil resize [options]
    hdiutil resize -help

    This is how my command looks like:

    sfroehlich-mbp:TimeMachine stivi$ sudo hdiutil resize 1t -shrinkonly /Volumes/TimeMachine/sfroehlich_mbp.sparsebundle/

    Any idea?

    Thanks :)

    • “-size” key is missing.

      • thks for your comment.

        apart from that, i have the problem now, that I can’t mount the volume without actively backing up so the way it is done here doesn’t work for me because when u remove the backup disk in TM there is no way to mount and access to backup volume.

        any idea how to solve this issue?

        thanks in adance!

  3. Same problem as @stivi here. the command in step 2 results in the following error:

    > hdiutil: resize: failed. No such file or directory (2)

    Seems like the cause is the disk image xxxxx.sparsebundle is NOT mounted (or has been unmounted after Time Machine has done its job).

    I tried to use “mount” and “mount_afp” commands to mount it, but couldn’t figure out how it’s done.

    How did you make step 2 work? Was TM running backup while you did it?

    Many Thanks!!
    (I’m using Mac OS X 10.6.8 and MyBook Live 2TB for NAS)

  4. Alright, just figured that out!

    Finder > Go > Connect to Server…
    > Enter in “Server Address”:
    afp://;AUTH=No%20User%20Authent@MyBookLive.local/TimeMachine

    Then “MyBookLive-tm” shows up under “SHARED” in the finder sidebar. Clicking on it shows “TimeMachine” as the root folder, which contains my xxxx.sparsebundle.

    Then I tried your step 2. You’re right, it hit the error “hdiutil: resize failed – error -5341″

    And the steps follows worked like a charm.

    Thanks @untoro


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.