Multi-DVD or (multi-CD) spanning backups with tar

Jun 23, '05 10:31:00AM

Contributed by: ruaric

I have never done a backup despite having had my iMac G5 for about 7 months. One of the reasons for this is I do not have an external disk. I realised I could backup to DVDs but have been put off by the hassle of organising my data in such a way that it fits into neat amounts that each fill a DVD. Of course I'm sure there are plenty of great software applications I could buy that would make things easier, but it occurred to me that since MacOS X is UNIX based I probably have all the tools I need to do a backup (or I could at least get them for free).

After a bit of thinking, I figured tar was probably the best option, since it allows for multi-part backups with the -M switch. Though I soon realised (after a few web searches) that the versions of tar included with Panther (my current OS) do not understand resource forks, and this could potentially cause me problems further down the line, should I need to restore (Tiger's tar does support resource forks).

A bit more searching on the web and I stumbled across hfstar and xtar, which are both variants of GNU tar, but do support resource forks (although they store the resource forks inside the tar in different ways, and are hence incompatible). In terms of features, there is nothing to choose between them; they do exactly the same thing. There was mention on one website that author of the page had encountered some errors with hfstar and switched to xtar (which fixed the issue). To be fair though this could be related to old problems that have since been fixed. Also there seems to be a greater number of people recommending hfstar than there are xtar (though this could be related to the fact that it seems to be older). I recommend you test both and see which works for you. I decided to go with xtar first but might try hfstar next time.

Anyway, below I have outlined the method I used to do the multi-DVD backup (it would also work with CDs). Feel free to change the instructions to make use of hfstar instead if you prefer. Or if you are a Tiger user, you can simply use the tar program provided. I would not advise using one version of a resource fork capable tar (hfstar, xtar, or Tiger tar) to back up and another one to restore. My understanding is that they all support resource forks in incompatible ways, so whatever you use to back up, you should also use to restore!

Here is the method:

  1. Close all applications (to prevent files being altered during backup).
  2. Place a blank DVD-R in the drive, and when you get the pop-up to name it, give it a suitable name e.g. "multipartdvdbackup".
  3. Start the terminal and issue the following commands:
    $ cd /
    $ sudo xtar -cvpMf /Volumes/multipartdvdbackup/backup.tar Users/
    
    Here is a breakdown of what the switches mean: You may also want to backup Applications/ and Library/ as well. If so add it on after them after Users/.
  4. Once the data to fill one DVD has been written, you will be prompted by xtar to change media. At this point, control-click the DVD on the desktop (e.g. "multipartdvdbackup") and choose "Burn." This will actually write the data to the DVD (up until now, it has only been written to a DVD image).
  5. Once burning is finished eject the DVD-R, label it something like "Part 1" with a pen, and stick in the next blank DVD-R. When prompted for a name, you must give it the exact same name as the previous DVD (including the same case).
  6. Go back to the Terminal window and hit Enter to start copying the next part.
  7. Once done, repeat steps four through six (changing step five only to label each part appropriately, e.g. "Part 2", "Part 3", etc.) until all your data is backed up.
You should now have a complete backup of all data in your /Users folder and its subdirectories (and optionally your /Applications and /Library folders as well).

To restore, you would simply stick in the first DVD, fire up the Terminal, and issue the following:
$ cd /
$ sudo xtar -xvpMf /Volumes/multipartdvdbackup/backup.tar
The -x flag tells xtar to extract the files from the archive.

I didn't bother compressing the data, since I figured that the extra time delay cause by running gzip would not be worth it (to me). I'd prefer use an extra DVD-R or two and save the time. However, if you wanted, you could add the -z switch to both the creation and extraction of the backup. A better option might be to install lzop (a very high speed compressor that does not compress quite as well as gzip but is a good deal faster) via Fink or DarwinPorts and invoke it via the switch: --use-compress-program=lzop.

Comments (40)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050609093101245