{"id":48,"date":"2008-08-08T16:50:52","date_gmt":"2008-08-08T23:50:52","guid":{"rendered":"http:\/\/www.dreness.com\/blog\/?p=48"},"modified":"2019-12-07T17:10:16","modified_gmt":"2019-12-08T00:10:16","slug":"hacking-time-machine","status":"publish","type":"post","link":"https:\/\/dreness.com\/blog\/archives\/48","title":{"rendered":"Hacking Time Machine"},"content":{"rendered":"<p>It&#8217;s &#8220;hack some shit up&#8221; Friday. Everybody ready?<\/p>\n<p>Have a Time Capsule or Mac OS X Server configured to provide network time machine backups? Of course you do! Let&#8217;s examine the client \/ server interaction.<\/p>\n<p>The Time Machine preference pane provides a list of available backup volumes. This list includes local volumes as well as network volumes. Mac OS X makes extensive use of multicast dns for service discovery, so let&#8217;s check there first. Get yourself a copy of <a href=\"http:\/\/www.tildesoft.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Bonjour Browser<\/a>, then fire it up and look under &#8216;local&#8217; for things that seem interesting. Ooo there&#8217;s one called &#8220;adisk&#8221;, let&#8217;s check in there&#8230;<\/p>\n<p><a href=\"http:\/\/www.dreness.com\/blog\/wp-content\/uploads\/2008\/08\/adisk.png\"><img loading=\"lazy\" decoding=\"async\" width=\"531\" height=\"112\" class=\"aligncenter size-full wp-image-58\" title=\"adisk\" src=\"http:\/\/www.dreness.com\/blog\/wp-content\/uploads\/2008\/08\/adisk.png\" alt=\"\" srcset=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2008\/08\/adisk.png 531w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2008\/08\/adisk-300x63.png 300w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/a><\/p>\n<p>From <a href=\"http:\/\/www.dns-sd.org\/ServiceTypes.html \" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.dns-sd.org\/ServiceTypes.html<\/a> we see:<\/p>\n<pre><strong>adisk<\/strong>          Automatic Disk Discovery\r\n                Bob Bradley &lt;bradley\u00c2\u00a0at\u00c2\u00a0apple.com&gt;\r\n                Defined TXT keys: sys, dkX<\/pre>\n<p>We could read a <a href=\"http:\/\/files.dns-sd.org\/draft-cheshire-dnsext-dns-sd.txt\" target=\"_blank\" rel=\"noopener noreferrer\">bit more<\/a> about service discovery via multicast dns to learn that:<\/p>\n<pre>DNS-SD uses DNS TXT records to store arbitrary name\/value pairs\r\nconveying additional information about the named service. Each\r\nname\/value pair is encoded as its own constituent string within the\r\nDNS TXT record, in the form \"name=value\".\r\n...\r\nThe intention of DNS-SD TXT records is to convey a small amount of\r\nuseful additional information about a service. Ideally it SHOULD NOT\r\nbe necessary for a client to retrieve this additional information\r\nbefore it can usefully establish a connection to the service. For a\r\nwell-designed TCP-based application protocol, it should be possible,\r\nknowing only the host name and port number, to open a connection\r\nto that listening process, and then perform version- or feature-\r\nnegotiation to determine the capabilities of the service instance.\r\nFor example, when connecting to an AppleShare server over TCP, the\r\nclient enters into a protocol exchange with the server to determine\r\nwhich version of the AppleShare protocol the server implements, and\r\nwhich optional features or capabilities (if any) are available.<\/pre>\n<p>Ok, so there&#8217;s a record there, and along with the standard parts of the record, there are two additional key \/ value pairs in the text record portion. The meaning of the keys and values is probably only known for sure by Time Machine and friends, but certainly some of that data looks familiar.<\/p>\n<p>First there&#8217;s the IPv4 address&#8230; that&#8217;s probably provided automatically when the record is published, based on the machine&#8217;s current IP address. IPv6 address follows, again we needn&#8217;t worry about that. The port number is listed at 9, which is &#8216;discard&#8217;, so this is probably not used. What port *is* used, then? Well, we know that Time Machine over the network supports either AFP or SMB, so it&#8217;s going to be one of those two. Seems like AFP would be most common, just since it is the APPLE file protocol and whatnot&#8230;<\/p>\n<p>Then we have the sys and dk0 items&#8230; well I dunno what waMA means (something something mac address?), but what follows certainly looks like a MAC address&#8230; and sure enough, it matches the MAC address on my Time Capsule.<\/p>\n<p>Note also that the second key in the shown record is dk0, whereas the spec says the defined TXT keys are &#8220;sys, dkX&#8221;. The &#8220;X&#8221; here suggests that there might be more than one of these keys, and they are numbered starting from 0 and counting up. Let&#8217;s pick appart the dk0 entry.<\/p>\n<pre>dk0=adVF=0xa1,adVN=backupz,adVU=AF9AC8F1-BCF5-3E63-9EBD-CD171CF5061B<\/pre>\n<ul>\n<li>adVF: no idea<\/li>\n<li>adVN: hmm&#8230; another &#8220;adV&#8221; prefix. air disk volume? air disk volume name?<\/li>\n<li>adVU: air disk volume UUID! (I think)<\/li>\n<\/ul>\n<p>Ok, now let&#8217;s have some fun. Fire up file sharing. Click the little + button to create a new share point. Select a folder \/ volume that has some eh&#8230; free space on it :) The name of the folder \/ volume as it appears in the list of share points is the AFP share point name, so we should try to use that for &#8216;adVN&#8217;.<\/p>\n<p>Next, use diskutil to find the UUID for the volume on which your new share point resides. The argument after &#8220;info&#8221; is the path to the volume. &#8220;\/&#8221; for the boot volume, &#8220;\/Volumes\/whatever&#8221; for something other than the boot volume.<\/p>\n<pre>sudo diskutil info \/ | grep \"UUID\"<\/pre>\n<p>Finally, find your system&#8217;s MAC address (the one that corresponds to your primary network interface).<\/p>\n<pre>netstat -rn | grep default | awk '{print $6}' | xargs ifconfig | grep ether<\/pre>\n<p>Now we should have enough information to try to create a record. Looking at the man page for dns-sd, we see the basic usage for registering a record is:<\/p>\n<pre>dns-sd -R name type domain port [key=value ...]<\/pre>\n<p>Let&#8217;s try it! We still don&#8217;t know what adVF is, so we&#8217;ll just use 0xa1 like the Time Capsule does and see what happens. In the command below, replace 00:11:22:33:44:55 with your MAC address, &#8220;Backupz&#8221; with your new share point name, and &#8220;AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE&#8221; with the UUID of the volume on which your share point resides.<\/p>\n<pre>sudo dns-sd -R \"Back it on up\" \"_adisk._tcp.\" \"local\" \"9\" \\\r\n        \"sys=waMA=00:11:22:33:44:55\" \\\r\n        \"dk0=adVF=0xa1,adVN=Backupz,adVU=AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE\"<\/pre>\n<p>You should see something similar to<\/p>\n<pre>Registering Service Back it on up._adisk._tcp..local port 9 TXT ...<\/pre>\n<p>Leave that window open. Open a new terminal window.<\/p>\n<pre>dns-sd -B _adisk._tcp<\/pre>\n<p>You should see your service instance listed. cntrl-c. Get the details:<\/p>\n<pre>dns-sd -L \"Back it on up\" _adisk._tcp local<\/pre>\n<p>Looks good. Now go to another mac on your local network. Open the Time Machine prefpane. Click &#8220;Choose Backup Disk&#8230;&#8221;.<\/p>\n<p><a href=\"http:\/\/www.dreness.com\/blog\/wp-content\/uploads\/2008\/08\/back-it-on-up.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-59\" title=\"back-it-on-up\" src=\"http:\/\/www.dreness.com\/blog\/wp-content\/uploads\/2008\/08\/back-it-on-up.png\" alt=\"\" width=\"176\" height=\"37\" \/><\/a><\/p>\n<p>Cool!<\/p>\n<p>Limited testing has shown that once you pick a network Time Machine disk in this fashion, the multicast dns service advertisement record is no longer needed. Apparently the Time Machine client caches the information about the location of the network disk. Also, probably a good idea to make sure that your network time machine volume is not guest-accessible&#8230;<\/p>\n<p>Here&#8217;s a little script to ease the process&#8230;<\/p>\n<pre>#!\/bin\/sh\r\n# Instructions:\r\n# 1. Use the Sharing preference pane to configure an AFP share point that will\r\n# be your network backup volume. Connect from another mac using Finder --&gt;\r\n# Connect To Server. Make sure you can log in. Note the name of the AFP volume.\r\n# 2. Use diskutil info to get the UUID from the volume on which your AFP\r\n# sharepoint resides.\r\n# 3. Customize the values below.\r\n\r\n# Customize here\r\nservicename=\"Back it on up\"\t\t# the name shown in parens in the TM browser\r\nmacaddy=\"00:11:22:33:44:55\"\t\t# MAC address of the AFP server\r\nvolname=\"backupz\"\t\t\t\t# AFP sharepoint name\r\nvoluuid=\"6E132F57-8292-4A73-9B37-5C0F82928E85\" # volume UUID \r\n\r\n# 4. Make sure this script is executable (chmod +x), then run it. You will be\r\n# prompted for your password (must be admin).\r\n# 5. Go to your other mac, use the Time Machine prefpane to select your shared\r\n# AFP volume. The other mac needs to be on the same local network.\r\n# 6. After selecting the volume, you can cntrl-c this script to stop it.\r\n# 7. Enjoy your network time machine backups!\r\n\r\n# no touchy\r\nservicetype=\"_adisk._tcp.\"\r\ndomain=\"local\"\r\nport=\"9\"\r\nadVF=\"0xa1\"\t\t\t# magic?\r\n\r\n# we need at least two key \/ value pairs, like such:\r\n# sys=waMA=00:1F:5B:34:BC:41\r\n# something something Mac Address, I guess...\r\n# dk0=adVF=0x0a1,adVN=TM Test,adVU=AF9AC8F1-BCF5-3E63-9EBD-CD171CF5061B\r\n# dkn iterates starting with dk0, then dk1... these are backup volumes\r\n# adVF is ... something. I used trial and error to find that 0xa1 works\r\n# adVN is volume name\r\n# adVU is volume UUID, which you can get from diskutil info.\r\n\r\n# dns-sd -R name type domain port [key=value ...]\r\nsudo dns-sd -R \"$servicename\" \"$servicetype\" \"$domain\" \"$port\" \\\r\n\t\t\"sys=waMA=$macaddy\" \\\r\n\t\t\"dk0=adVF=$adVF,adVN=$volname,adVU=$voluuid\"<\/pre>\n<p>Have fun :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s &#8220;hack some shit up&#8221; Friday. Everybody ready? Have a Time Capsule or Mac OS X Server configured to provide network time machine backups? Of course you do! Let&#8217;s examine the client \/ server interaction. The Time Machine preference pane &hellip; <a href=\"https:\/\/dreness.com\/blog\/archives\/48\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4,3,6],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-development","category-os-x","category-os-x-server","category-scripts"],"_links":{"self":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":13,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":1015,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/48\/revisions\/1015"}],"wp:attachment":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}