Monday, September 19, 2011

MacOS X 10.7 Time Machine Backup to FreeBSD Server with Netatalk

UPDATE : This documentation still works, but it uses netatalk version 2 and is more complex than using version 3. Please consider using this documentation using netatalk version 3 instead. 

If you backup your MacOS X 10.6 machine to a netatalk server, then you may have found that MacOS X 10.7 cannot backup to the same machine. Apparently, the major reason why it's now broken is a lack of « replay cache » which was introduced in AFP 3.3. So what you need to do is upgrade netatalk to version 2.2.x.

UPDATE : I've successfully this setup with MacOS X 10.8 and 10.9.

Let's configure a FreeBSD machine to serve as a Time Machine target for MacOS X 10.7. I'm using FreeBSD 8.2 as this is the production version. If you prefer using a Linux machine, then take a look at this blog post by Steffen L. Norgren.

First, install the latest version of netatalk

sudo portsnap fetch
sudo portsnap extract
cd /usr/ports/net/netatalk
sudo make install clean

Then, create a directory where your backup will reside. I use the /export file system, but you can obviously place your backup anywhere you like. Just make sure it doesn't fill your root, /usr and /var partitions.

sudo mkdir -p /export/backup/drobilla

Set the permissions to the same user on both your MacOS X and FreeBSD server. To find out what's your user ID and group ID on your MacOS X machine, open up Terminal and issue the id(1) command:

id
uid=501(drobilla) gid=20(staff)

Create these same UID and GID on the FreeBSD machine and set the new user's password.

sudo pw groupadd -g 20 staff
sudo pw useradd drobilla -u 501 -g 20 -d /usr/home/drobilla \
     -s /usr/local/bin/bash -c "David Robillard"
sudo passwd drobilla

Then set the permissions to the backup directory.

sudo chown drobilla:staff /export/backup/drobilla

Now configure netatalk. This is done by editing several files:

1. /usr/local/etc/AppleVolumes.default
2. /usr/local/etc/AppleVolumes.system
3. /usr/local/etc/afpd.conf
4. /usr/local/etc/netatalk.conf
5. /etc/rc.conf

Let's start with AppleVolumes.default.

sudo vi /usr/local/etc/AppleVolumes.default

<AppleVolumes.default>
# /usr/local/etc/AppleVolumes.default
#
# See /usr/local/AppleVolumes.default.dist for more information.
# There is only two lines in this file.

:DEFAULT: options:upriv,usedots

/backup/drobilla "Backup David" allow:drobilla cnidscheme:dbd options:tm volsizelimit:300000

# EOF
</AppleVolumes.default>

Then the AppleVolumes.system is actually an empty file. So just create it with the touch(1) command. For more info on this file, check the /usr/local/etc/AppleVolumes.system.dist file.

sudo touch /usr/local/etc/AppleVolumes.system

Now we configure AFP.

sudo vi /usr/local/etc/afpd.conf

<afpd.conf>
# /usr/local/etc/afpd.conf
#
# Again, see /usr/local/etc/afpd.conf.dist for more info.
# This file has a single line.

- -tcp -noddp -uamlist uams_dhx.so,uams_dhx2.so -setuplog "default log_info" -cnidserver 127.0.0.1:4700

# EOF
</afpd.conf>

And the /usr/local/etc/netatalk.conf file. Note that you can change your ATALK_NAME to something other then FreeBSD. This is the name that will show when you will connect via your MacOS X machine.

sudo vi /usr/local/etc/netatalk.conf

<netatalk.conf>
# /usr/local/etc/netatalk.conf
#
# See /usr/local/etc/netatalk.conf.dist for more info.

AFPD_MAX_CLIENTS=20
ATALK_NAME=FreeBSD
ATALK_MAC_CHARSET='MAC_ROMAN'
ATALK_UNIX_CHARSET='LOCALE'
AFPD_GUEST=nobody
CNID_CONFIG="-l log_note"

# EOF
</netatalk.conf>

And finally, we must edit our rc.conf file to enable the new daemons. Note that there is quite a lot more in the rc.conf file, but I've just listed the ones required for the purposes of this blog post.

sudo vi /etc/rc.conf

<rc.conf>
afpd_enable="YES"
atalkd_enable="NO"
cnid_metad_enable="YES"
netatalk_enable="YES"
</rc.conf>

Optional: now we need to tell syslog to send all AFP related messages to the afpd.log file. So add those two lines at the end of the syslog.conf(5) file.

sudo vi /etc/syslog.conf

<syslog.conf>
!afpd
*.* /var/log/afpd.log
</syslog.conf>

Be sure to restart syslog to enable those changes. But first make sure the file exists.

sudo touch /var/log/afpd.log
sudo /etc/rc.d/syslogd restart

And make sure this new file gets rotated so as to prevent it from growing too big. Add a single line to the newsyslog.conf(5) file.

sudo vi /etc/newsyslog.conf 

<newsyslog.conf>
/var/log/afpd.log root:wheel 640  7     1024 *     J
</newsyslog.conf>

Then you can start your netatalk daemon:

sudo /usr/local/etc/rc.d/netatalk start

Be sure to check the system's log to see if everything has started as it should. This is also a good place to check when clients connect to the AFP service.

sudo tail /var/log/messages

That's it from the FreeBSD side. Now take your MacOS X 10.7 machine and connect to your FreeBSD machine. To do so, hit Command-K and type your FreeBSD server's IP address.

afp://192.168.1.2

At the prompt, enter the user name and password that we just created on the FreeBSD server.

You will see a list of shares that we configured in the /usr/local/etc/AppleVolumes.default file. Select the Backup David share. It will be mounted.

Now open up the Time Machine preferences and select a disk. You should see your new FreeBSD disk there. Select it and run the backup.

HTH,

David


4 comments:

  1. Where do you set how large the volume is for the folder being shared over netatalk? I have a export partition just shy of 900GB but in OS X Lion it only shows up as 314GB.

    Brian

    ReplyDelete
  2. @Brian: the partition size is configured in the AppleVolumes.default file via the keyword « volsizelimit ». In my example above, I've set the volsizelimit to 300000. You can obviously either remove this keyword entirely or change it's value. I do think you must disconnect your Mac from the volume and restart the daemons on the FreeBSD server for when you change this value.

    HTH,

    David

    ReplyDelete
  3. Thanks David, I re-read the comments within the AppleVolumes.default files and noticed this volume limit shortly after I posted this question. Thanks for your reply.

    Brian

    ReplyDelete
  4. @Brian: my pleasure :) Note that you can also use this setup for plain data volumes available to all your Mac OS machines if you'd like. For example, share music, pictures and movies between the various Mac OS machines in your network. Or have a single iTunes music library shared with all your machines.

    ReplyDelete

Note: Only a member of this blog may post a comment.