I need more Time (Machine)

This is a continuation of an earlier post I did on Time Machine. While investigating all the many Time Machine features and issues, I discovered a nice add-on tool called tms. It currently is in beta and only exists as a command-line tool. It interacts with the Time Machine database on the Time Machine destination (physical disk or network) and provides some very useful information:

snapshots – List the snapshots present on the destination

$ tms snapshots
/Volumes/Backup1/Backups.backupdb/media/2008-09-06-193341: num=5760 state=4 type=2 ver=1 start=2008-09-06-19:22:21.618534 complete=2008-09-06-19:33:41.893965
/Volumes/Backup1/Backups.backupdb/media/2008-09-06-153237: num=5759 state=4 type=2 ver=1 start=2008-09-06-15:16:21.145156 complete=2008-09-06-15:32:37.095843
/Volumes/Backup1/Backups.backupdb/media/2008-09-06-113449: num=5758 state=4 type=2 ver=1 start=2008-09-06-11:17:09.578714 complete=2008-09-06-11:34:49.347916
{snip}

snaplog – List all the log detail for the latest (or specified) backup. I won’t paste it here as it is very verbose and quite informative.

log – List the revisions of a particular file

$ tms log wp_ozh_adminmenu.php 
/Volumes/Backup1/Backups.backupdb/media/2008-02-28-002700/path/to/wp_ozh_adminmenu.php: num=2658 oldest=2008-02-24-22:18:09 newest=2008-04-18-22:56:42
/Volumes/Backup1/Backups.backupdb/media/2008-05-27-004103/path/to/wp_ozh_adminmenu.php: num=4630 oldest=2008-05-26-00:23:11 newest=Current

delta – List the differences between two backups

$ tms delta 5760 5759
delta: 5760 vs 5759
/Volumes/MediaHD/.DS_Store: !=
/Volumes/MediaHD/private/var/amavis/tmp/amavis-20080906T154248-92402: ->
/Volumes/MediaHD/private/var/amavis/tmp/amavis-20080906T130623-87446: <-
/Volumes/MediaHD/Library/Preferences/com.apple.iPod.plist: !=
/Volumes/MediaHD/Library/Preferences/com.apple.SoftwareUpdate.plist: !=
{snip again}

For the notation at the end of the line, != means the file is in both backups but are different (e.g., it changed), <- means the file is in the later backup but not in the earlier, and -> means the file is in the earlier but not later.

diff – Display the differences between two backups of a file using the diff command. For some reason, this doesn’t work for me.

I’ve used tms to help isolate what is being backed up and since I am running Leopard Server, there are many changing files that I have excluded which has reduced the amount of data being backed up.

Twitter Updates for 2008-09-04

  • What do people have against noses. Shouldn’t a smiley be :-) or :^) instead of :) ? #
  • Walking with a friend discussing GTD and OmniFocus. #
  • I think I’m going to remove due dates from most of my OmniFocus items. Having so many behind is just causing stress. #
  • iPhone browser FTW! Apple Genius wasn’t going to replace 2.5 yo MBPro power adapter until I pulled up the KB article (TS1977). #

I learned all about Time (Machine) so you don’t have to

I’ve been learning a lot about the Time Machine feature of Apple’s OS X 10.5 (Leopard) and wanted to take the time to share my experience. In a nutshell, Time Machine watches the files that get modified on your system and copies them to a secondary hard drive or network volume so that you have automatic backups available for anything that was deleted or modified.

It is a very nice user experience and it takes a lot of the work out of making backups. Of course, by taking work out Apple is really just making decisions for the majority of users and for most users, that decision is quite acceptable. I’m not most users. Fortunately, Apple directly or indirectly provides methods for changing the behavior of much of the OS and Time Machine is no exception. Here are many of the things that I’ve gathered over the last few months that might benefit you if you want to get more out of your experience.

Overview

I won’t go into too much detail as I’m going to presume you’ve already used Time Machine and are familiar with how it works. Generally, it performs a backup of your system every hour to an external drive. It is efficient in that only the modified files are copied. Hourly copies are kept for for 24 hours, daily copies for a month, and weekly copies until the destination drive fills up. You are free to put other data on that Time Machine disk, but it will eventually consume all available space.

Space is pretty efficiently used in that a file is copied only if it has changed but ineffecient in that a small change to a large file results in the entire file being backed up again. This can be a problem if the file really is big and changes frequently. This is the case with the virtual hard disk used for a virtual machine under VMware Fusion or Parallels Desktop.

Backing-up to a network volume

Any self-respecting geek has more than one computer in his or her home. Often times, you are using a laptop and have a dedicated computer with more storage sitting by your TV or in the den, closet, or garage. Unfortunately, while Time Machine can back up to a network volume, by default it only supports a specially presented volume served via Apple’s network filling protocol (AFP) from Leopard Server. You can back up to other choices (e.g., Windows or Linux) via Microsoft’s filing protocol (CIFS). To do this, you first need to have a native Apple file system to copy the data to.

Creating a sparseimage

OS X has supported disk images since the beginning but has recently added a format called sparseimage that starts small but grows as more data is added to it. To use a network volume, you first need to create the image that your machine will be storing the actual data in. Type the following on a mac creating the disk on a local hard drive first:

hdiutil create -library SPUD -size $SIZESPEC -fs HFS+J -type SPARSEBUNDLE \
-tgtimagekey sparse-band-size=262144 -volname "Backup of $MACHINENAME" \
$MACHINENAME_$MAC.sparsebundle

Here are explanations on the options that you’ll want to change:

$SIZESPEC – the size of the virtual disk when filled. A good choice is twice the size of what you’re backing up.

$MACHINENAME – The name of your machine

$MAC – The network address of the primary network interface without separators (e.g., aabbccddeeff0011). You can get this from System Profiler or Network Utility.

For education purposes, here is some explanation of some of the other items:

-fs HFS+J – make the filesystem HFS+ with Journaling (the default OS X filesystem)

sparse-band-size – the size of the ‘chunks’ that make up the sparseimage (they aren’t just one single file). Normally, the images are made in 8M chunks but those perform quite poorly over the network. The value provided above represents 128M chunks (2 * 128 * 1024 512-Byte-Blocks = 262144 = 128MB) which is a good size for a hard disk backup.

Copying the image to to the network volume is as simple as dragging the sparseimage file via the Finder or do it in the terminal:

cp -r $MACHINENAME_$MAC.sparsebundle /Volumes/path/to/destination

The last part is to tell the system to allow any network volume as a destination and not just AFP:

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

Using just part of a drive

For some reasons you’ll see below, I wanted to limit the usage of the destination drive local to the system. Normally, Time Machine will use all the space of an external drive chosen as the destination. If you are storing other information on it, that can become a problem. The solution is to convert the physical Time Machine destination volume into a disk image.

The first step is to create a disk image with the same information above. Next, mount the newly created disk image:

hdiutil mount /path/to/created/imagefile

You can also mount it simply by double-clicking on the disk image file. You’ll then copy the contents of the current Time Machine volume to the created disk image. Note, it is best to ensure Time Machine is disabled as you don’t want anything changing as you are copying it:

sudo asr restore --source /Volumes/srcvol --target /Volumes/Backup\ of\ $MACHINENAME

asr is Apple’s System Restore utility and it performs copy between volumes but ensures that everything is copied properly. You need the sudo portion to have the command be able to access every file which may not be the case if run just as yourself.

Of course, this copy can take some time depending on the speed of your system but mostly due to the size of the data being copied.

Once completed, you can unmount the disk image and configure Time Machine to use the disk that the disk image is stored on. Time Machine is smart enough to use the image if it sees it (the file has to be at the top-level of the destination hard drive).

Trigger a Time Machine backup from the command-line

If you ever want to trigger a Time Machine backup on a system from the command-line, perhaps on a remote system via ssh, issue the following command:

/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper -auto

Exclude an individual file from being backed up

You can exclude files from being backed up (like previously mentioned virtual disks) using the GUI in the Time Machine preferences (under Options), but it can also be done using the extended attributes in the command-line:

xattr -w com.apple.metadata com_apple_backup_excludeItem /path/to/file/to/exclude

Similarly, you can see if a file is being excluded but listing the extended attributes:

xattr -l /path/to/file/in/question

Hide the Time Machine disk in the Finder

If you aren’t getting all fancy and writting to a disk image, you may want to hide the destiation disk. You can do that just by making the volume invisible:

SetFile -a V /path/to/Time/Machine/Volume

Conclusion

I hope this has been helpful to you and that with the information are able to make a useful tool even more useful. To give credit where credit is due, I’ve included below the links to where much of the information was originally found.

Update

20090527 I’ve revised the sparse-band-size value from 1G to 128M which is the largest band currently support in 10.5.7. Files with larger band files cannot be mounted in 10.5.7. Once I determine the correct procedure for converting an old image, I’ll post a new article. In the meantime, you can get more information here.

Reference

10.5: Set up Time Machine on a NAS in three easy steps

10.5: Improve networked Time Machine performance

Man page for hdiutil

Man page for asr

Exclude Items From Time Machine Backup With Contextual Menu

Time Machine Exposed!

Hide Time Machine’s icon in the Finder

Soon, you won’t be able to believe your eyes

Siggraph is an annual convention where companies and universities get together and impress each other as they each increase the state of the art of computer graphics.

This year seems no different. Two papers that seemed quite interesting were one on improving the attractiveness of faces in pictures and the other on replacing the face in a picture with another one but the one that really blew me away was the one on enhancing video using static images.

Not believing what you were seing had long been limited to the big screen or individually doctored photographs, but it will soon be hard to trust almost anything you don’t personally witness.

Project 68

As most folks know I have quite a commute. Fifty-six miles door-to-door. It can be a bit of a drag at times, but it was the known down-side when we decided to move up here twelve years ago.

With the increasing price of gas, there is a growing trend for “hypermilers” which are folks that try to get the absolute maximum gas mileage out of their cars. To really make it work, you need to make physical modifications like adding airdams and spoilers. I read an article on it last week and heard that my car (a Honda Civic) is a popular model.

I’m not inclined to put any money into the effort, but I can certainly slow down. I decided, somewhat arbitrarily, to limit myself to 68 mph. It’s a fair amount lower than the 80 or so that I often go. Now, before you react, that speed on I-15 north of Escondido is quite common.

I’ll try to remember to post an update on how it’s going in a week or two.