Create a fixed size network storage for Time Machine

Time Machine is a backup program built into Mac OS 10.5, Leopard. It saves all files on the computer on a USB  or network drive, which can be used for restoration of individual files or the whole computer.

The normal behavior of Time Machine is to keep

  • hourly backups for the past 24 hours
  • daily backups for the past month
  • weekly backups until your backup disk is full

It is the last point that might cause some trouble for some people, since many people might share the drive with other type of data. There has to be some way to limit the size of the backup volume. This is my approach.

Preparing an image

The first step is to create an image to hold the backup filesystem. If you want this filesystem encrypted, have a look at Mounting encrypted volumes, otherwise just follow the following steps. The image will be created as /ext/timemeachine.img and it will be mounted in /ext/timemachine.mnt.

dd if=/dev/zero of=/ext/timemachine.bin bs=1G seek=250 count=1
losetup /dev/loop1 /ext/timemachine.bin
mkfs.ext3 /dev/loop1
tune2fs -c0 -i0 /dev/loop1
losetup -d /dev/loop1
mkdir /ext/timemachine.mnt

The first thing is to create an image file, and using the dd command we create an empty 250GB file, which will contain the backups. The next step is to setup the image as a loop device, which makes it possible to mount it as usual. loop1 is currently used, but if you know that it is occupied, feel free to choose another device.

The next step is to edit /etc/fstab and add a line which will automatically mount the filesystem when the computer boots.

/ext/timemachine.bin /ext/timemachine.mnt ext3 loop=/dev/loop1 0 0

Then we will mount all filesystems and verify that it has indeed been mounted.

df -h
/ext/timemachine.bin  248G  188M  235G   1% /ext/timemachine.mnt

There should be a line like the above if everything is working correctly. The last step is to set the correct permissions for the directory for your user.

chown -R joch /ext/timemachine.mnt/

Setting up the Samba share

To connect to the server, it is necessary to setup the Samba server. Create a share like the following in /etc/samba/smb.conf.

[tmbup]
comment = Time machine backups
path = /ext/timemachine.mnt
browseable = yes
read only = No
inherit permissions = no
guest ok = no
printable = no

Now just reload Samba and add a user if you have not done so before.

invoke-rc.d samba reload
smbpasswd -a joch

Setting up Time Machine

Connect to the share in Finder as usual.

Finder window

Open up the Time Machine preferences and click Change Disk. It should give you a dialog like this, and Time Machine should then be enabled.

Time Machine setupTime Machine enabled

If you get the error “Time Machine Error: The backup disk image could not be created.”, you will need to do some magic on the server.

Time Machine error

You need to start the backup once again, but this time you will have to be quick and copy the directory it creates on the server. Once Time Machine has finished, the original directory will be deleted, so just copy the saved directory back to the same place.

cp -rp Johnnys\ MacBook\ Pro_001ec2123456.sparsebundle/ ..
# Wait until Time Machine has finished
cp -rp Johnnys\ MacBook\ Pro_001ec2123456.sparsebundle/ timemachine.mnt/

Now run the backup again, and it should complete successfully!

Time Machine run

This behaviour is very strange, but the above trick always solves the problem.

3 thoughts on “Create a fixed size network storage for Time Machine

  1. Cesar

    Thanks for the tip. It almost solved my problems…
    Even after trying your trick I still got the message:
    “Time Machine Error: The backup disk image could not be created.”

    After a bit of Googling I found a ‘proper’ solution. It seems that
    there is a bug that prevents the creation of the sparsebundle. The
    solution is to create a sparsebundle first on your local drive, and
    then move it to the Samba share. The details:

    http://www.readynas.com/?p=253

    And by the way, with the solution above it is also possible to limit
    the size of the sparsebundle, so it’s not needed to create an image to
    hold the filesystem.

    Reply
  2. Johnny Chadda Post author

    [quote post="344"]And by the way, with the solution above it is also possible to limit
    the size of the sparsebundle, so it’s not needed to create an image to
    hold the filesystem.[/quote]
    Great! Thanks for the tip!

    Reply
  3. Pingback: » Limit Time Machine disk usage on external drives Johnny Chadda .se

Leave a Reply