rageek

A place for Unix Thoughts and Ideas

Taming OSX Time Machine Backups

OSX’s Time machine backup feature is very simple to enable and to use.

Unfortunately, it is almost too simple and there are no mechanisms for capping the amount of storage used for backups and it will eventually grow and take over any sized drive.

Really the best way to work with it is to dedicate a partition to just Time Machine and nothing else.

Time Machine will prune backups as they age and  when you run out of space, but depending on that functionality is very limiting.

It turns out that Time Machine has a very handy command line interface called tmutil for listing and deleting backups. It also has some additional compare commands that look like they could be very useful for tracking down changed files.

m-m:~ $ tmutil
Usage: tmutil help <verb>

Usage: tmutil version

Usage: tmutil enable

Usage: tmutil disable

Usage: tmutil startbackup [-b|--block]

Usage: tmutil stopbackup

Usage: tmutil enablelocal

Usage: tmutil disablelocal

Usage: tmutil snapshot

Usage: tmutil delete snapshot_path ...

Usage: tmutil restore [-v] src dst

Usage: tmutil compare [-a@esmugtdrvEX] [-D depth] [-I name]
       tmutil compare [-a@esmugtdrvEX] [-D depth] [-I name] snapshot_path
       tmutil compare [-a@esmugtdrvEX] [-D depth] [-I name] path1 path2

Usage: tmutil setdestination mount_point
       tmutil setdestination [-p] afp://user[:pass]@host/share

Usage: tmutil addexclusion [-p] item ...

Usage: tmutil removeexclusion [-p] item ...

Usage: tmutil isexcluded item ...

Usage: tmutil inheritbackup machine_directory
       tmutil inheritbackup sparse_bundle

Usage: tmutil associatedisk [-a] mount_point volume_backup_directory

Usage: tmutil latestbackup

Usage: tmutil listbackups

Usage: tmutil machinedirectory

Usage: tmutil calculatedrift machine_directory

Usage: tmutil uniquesize path ...

Use `tmutil help <verb>` for more information about a specific verb.

The following is a example of listing my backups and then deleting one.

m-m:~ $ tmutil listbackups
/Volumes/Data/Backups.backupdb/m-m/2012-10-01-085459
/Volumes/Data/Backups.backupdb/m-m/2012-10-02-081339
/Volumes/Data/Backups.backupdb/m-m/2012-10-03-091919
/Volumes/Data/Backups.backupdb/m-m/2012-10-04-093621
/Volumes/Data/Backups.backupdb/m-m/2012-10-05-110813
/Volumes/Data/Backups.backupdb/m-m/2012-10-08-085751
/Volumes/Data/Backups.backupdb/m-m/2012-10-10-102952
/Volumes/Data/Backups.backupdb/m-m/2012-10-12-091849
/Volumes/Data/Backups.backupdb/m-m/2012-10-15-090719
/Volumes/Data/Backups.backupdb/m-m/2012-10-16-092153
/Volumes/Data/Backups.backupdb/m-m/2012-10-19-090310
/Volumes/Data/Backups.backupdb/m-m/2012-10-22-090616
/Volumes/Data/Backups.backupdb/m-m/2012-10-23-090313
/Volumes/Data/Backups.backupdb/m-m/2012-10-24-094128
/Volumes/Data/Backups.backupdb/m-m/2012-10-25-093620
/Volumes/Data/Backups.backupdb/m-m/2012-10-26-092053
/Volumes/Data/Backups.backupdb/m-m/2012-10-30-090916
/Volumes/Data/Backups.backupdb/m-m/2012-10-30-095501
/Volumes/Data/Backups.backupdb/m-m/2012-10-30-105802
/Volumes/Data/Backups.backupdb/m-m/2012-10-30-115557
/Volumes/Data/Backups.backupdb/m-m/2012-10-30-125514
/Volumes/Data/Backups.backupdb/m-m/2012-10-30-135505
m-m:~ $ sudo tmutil delete /Volumes/Data/Backups.backupdb/m-m/2012-10-30-135505
Password:

We can also run this in looped fashion to delete multiple backups

tmutil listbackups | egrep '2012-10-[01].-' | while read backup; do echo "Deleting $backup"; sudo tmutil delete $backup;done
Deleting /Volumes/Data/Backups.backupdb/m-m/2012-10-01-085459
Password:
Deleting /Volumes/Data/Backups.backupdb/m-m/2012-10-02-081339
..
..
..
Deleting /Volumes/Data/Backups.backupdb/m-m/2012-10-19-090310

Using tmutil you can take control of the aging of backups on your machine.

But as I mentioned, it is probably best to dedicate a drive or partition to Time machine.

That being said, if you want to delete all backups and start over. First, go into time machine and select “Do not backup.”  You then can remove Backups.backup directory. Running a standard delete will take forever.

Here is the quick way to bypass all permissions and acl’s and remove the backup directory:

m-m:~ $ sudo /System/Library/Extensions/TMSafetyNet.kext/Contents/MacOS/bypass rm -rf /Volumes/Data/Backups.backupdb
Password:
Advertisements

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: