Is there any way to limit the number of versions time machine keeps of files?

In this case, I want time machine to back up some of my Virtual Machines. However, Since VM images are very large and monolithic, using the VM results in a 25 GB file that has to be backed up in it's entirety again.

However, I do want to have at least one version of the VM backed up, as a disaster prevention measure.

Is there any way to limit the history-depth that time machine keeps for certain files? I really want the extended backup that you get of everything else. Just letting the time machine drive fill up, and lose the oldest backups to a bunch of giant VM images is not an acceptable solution

Is there any way to modify time-machine backups using the terminal? I can see using some OS X cron analog to run a script that periodically deletes extra VM backups.

  • Would a solution that prunes these files after they get written be acceptable? (Or are you solely looking to hack the inclusion of a file before it gets considered by the backupd daemon?) Accelerated cleanup of files that get written is more doable / less risky in Lion. I think/vote it's a great question BTW. – bmike Oct 10 '11 at 17:57

Since you don't want no as an answer, and since Time Machine is proprietary software that you cannot modify you only have two options (don't complain, you asked for it)

  • convince Apple to implement the missing feature
  • implement your own version of Time Machine

You could modify backups from the terminal or with the Finder: backups are just directories with hard links but beware that you will most likely make them unusable by Time Machine (as Time Machine relays on the fact that the backups are as they were created).

There is a function in Time Machine "Delete all backups of" which removes backed up copies of a file. You could research if this is scriptable (Apple Script or terminal). I had no luck but seems the only way to periodically clean up a backup (with cron or similar)

You didn't specify which virtualization software you are using. If it's VirtualBox there is a workaround to reduce the size of the backed up data using snapshots: http://blog.matteocorti.ch/?p=331

  • The time-machine format is well enough understood that third party applications can understand the data ( twinforces.com/frictionless/time_machine_perspective.html tri-edre.fr/english/backintime.html ). Just because something is proprietary does not mean it cannot be changed. There is a little thing called reverse engineering. Considering some of the limitations of time machine, I am surprised that no one of a more technical bent has spent some time understanding it's filing system. – Fake Name Oct 10 '11 at 11:17
  • Furthermore, I believe that 10.7 has added a command line time-machine interface. – Fake Name Oct 10 '11 at 11:18
  • Basically, your answer is exactly what I was trying to avoid. A vacant "Go talk to Apple". With vague warnings of breaking things, and no useful info. I am willing to break things, if I can learn from it. – Fake Name Oct 10 '11 at 11:20
  • There is a culture of passivity present in the Mac world I do not understand. Dammit, this is a unix-based OS. The answer to functions you want is hack it, not "go plead for apple to add it". I have had similar responses to the other few questions I have asked about tweaking core GUI components. There is nothing inviolate or sacred about the the way the OS is designed. I'm interested in hacking core bits. The answer to questions about what I would have to tweak or modify is not "you cant". – Fake Name Oct 10 '11 at 11:27
  • @FakeName: I'll try to ignore your sarcasm. Of course the format is well known. The problem is that TimeMachine expects to find what it created. The point with undocumented API is that they are undocumented and they can change (but your choice, your risk). You asked for snow leopard, BTW tmutil does not have the requested feature (yes I checked). If you believe that Unix means free/hackable you are wrong. If you want to use a Unix tool do it and avoid Apple products. – Matteo Oct 10 '11 at 11:42

Time Machine backups can be accessed like any other disk (more or less), so you could start with something like the following as root:


# root directoy of backup history

# path where VM data is stored (relative to $TM_ROOT/timestamp)

# stop backup (if any)
tmutil stopbackup
tmutil disable

# get working
cd "$TM_ROOT"
LATEST=$(ls -l | grep -e '->' | cut -c 56-)

for dir in 2*; do
    if [[ "$dir" != "$LATEST" ]]; then
        # remove echo for destructive effect
        echo rm "$dir/$VMPATH/*"

# enable backup again
tmutil enable

Paths will need changes (Fourecks is my local machine). For Snow Leopard, just leave out the calls to tmutil.

CAUTION: I did not test this! You may also need chmod to change the ACLs of the files you want to delete (and the folder containing them) because the default ACLs for TM backups prevent you from deleting on shell level.

  • What will happen at the next backup when TM expects the file to be there? Are you sure it will not damage your backup? As stated above: your choice, your risk but a backup is something where there should be no risk: it has to work (always). – Matteo Oct 10 '11 at 11:46
  • There is no real difference for TM whether you delete a file manually or via the TM application. The content of the next backup is determined by the list of changed files, not by any history. And please be aware tha I would solve the problem raised in question differently (by taking a copy of the VM and excluding the VM directory from TM). I posted the script mainly to stay in line with the constraints of the question. – nohillside Oct 10 '11 at 12:08
  • if the file is not changed TM will not create a copy of it, but will create a hard link to the old copy. If this is deleted what happens? – Matteo Oct 10 '11 at 12:10
  • Only one hard link gets deleted, not the others. The file only 'disappears' after the last hard link is removed. To test in Terminal: touch foo; ln foo bar; ls -l foo bar, notice the link count (2) for both files. rm foo; ls -l bar, link count down to 1 again. – nohillside Oct 10 '11 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .