James Badger

Web Developer

Time Machine Auto-Mount 2013

A few months ago, I explained how to setup Time Machine to auto-mount over AFP to a remote server. This process still works for me, but I would like to note that there is an easier method to try first.

Open the Time Machine preference pane in System Preferences, and click “Select Disk…”. Select your network share. Done.

I am not sure why this did not work for me last year, but I did switch my remote server to use Netatalk 2.2.2 for Ubuntu.

Generate a New Secret Token for Rails Apps

Recently I had to build one Rails app off a clone of another Rails app. I wanted to find a quick way to change the secret token in config/initializers/secret_token.rb. IRB makes it easy:

$ irb
>> require 'securerandom'
=> true
>> SecureRandom.hex(64)
=> "3fe397575565365108556c3e5549f139e8078a8ec8fd2675a83de96289b30550a266ac04488d7086322efbe573738e7b3ae005b2e3d9afd718aa337fa5e329cf"
>> exit

Edit: Rails has actually built-in a Rake task (since 2007) to do this as well:

$ rake secret

Mountain Lion: Time Machine Over AFP, Auto-mount Edition

Update April 2013: Check out an easier way to do this. If that does not work, feel free to attempt the instructions below.

Apple’s Time Machine is designed to backup to external disks or Time Capsule network shares. It was discovered pretty quickly after it’s OS 10.5 release that any AFP share could be used as a backup destination, allowing one to use any AFP server as a destination for their Mac. The procedure has changed since, in 10.6, and 10.7. 10.8 fortunately works identically to 10.7, which I will quickly review:

  1. Use Disk Utility to create a new disk image to hold your backups. Name it whatever you want. Give it a size that it can expand to, it will automatically consume more disk space as necessary to hold backups until this size is reached (When the max size is reached, Time Machine will automatically start removing old backups). Use “Mac OS Extended (Journaled)” format, and optionally add encryption. I recommend you do, as you are keeping the backups on a network share and it shouldn’t impact backup speed. Set the Image Format to “sparse bundle disk image”. Save it directly to the network share for your backups.
  2. Open the disk image from the network share, and it should appear on your desktop. Using the terminal, type in sudo tmutil setdestination "/Volumes/<volume name>", substituting in the name of the mounted backup disk image for <volume name>, and hit return. Changing the Time Machine backup directory requires administrator privileges, which Terminal will ask you for.
  3. Using either the Time Machine menu bar item or system preference pane, run a backup. Time Machine will copy your backup into the mounted disk image as it works; open the volume to see a new “Backups.backupdb” folder with your saved data. Once Time Machine is finished, you can un-mount your backup volume and network share.
  4. The next time you want to backup, mount your network share and mount your backup image. Then, run Time Machine manually.

This alone is pretty handy, but having to manually mount your backups to run Time Machine is a waste of time. Fortunately, we can run one command in the terminal to tell Time Machine to automatically mount the network share for us:

Scoped Views in Rails_admin

If you have been programming with Rails for a few months, you have probably heard of some of the drop-in administration frameworks. Include it into your app, and you have a simple interface for editing all your models — no trips to the database or console necessary.

Here is the situation: You have a model that must past administrator review, and use an approved flag to filter the models; those that are approved are viewable on your site. Rather than code up a custom interface for displaying the models with an approved flag of false, you would rather use the administration interface to do the work for you. If you are already using ActiveAdmin, you can define a scope on a model and it will automatically add list filters to the interface. If you chose to use RailsAdmin (like me), that doesn’t work, you have to manually scan through the list to see those with the approved flag set to false.