Create backups of audio and other CDs via the Terminal

Feb 11, '04 08:14:00AM

Contributed by: shankarac

I hate to backup my audio CDs using iTunes, because it keeps a copy in its library. So I wrote a shell script to backup the CDs. The script uses cdrdao (CD read Disk At Once, which can be installed using fink) to read the CD raw and burn them. When a CD is read, cdrdao creates a toc (table of contents file) which holds the description of the CD type, and information about which file holds the raw data. As a bonus, this script will also backup VCDs and DataCDs!

[robg adds: I haven't tested the following script...]

When you insert a CD, the Finder will take over and launch an appropriate application. To read the data using cdrdao, the device should be "unmount"ed. I use disktool to detect the mounted device and to unmount it automatically.


-------- copycd --------
#!/bin/bash
#Jan 29, 2004 06:46 PM Shankar Chakkere
#This script will make a diskimage of the AudioCD, VCD and DataCD.

#Enable the following line if you have Superdrive
#You might have to add IODVDServices/1 
#or IODVDServices/2 if you have multiple drives
DEVICE=IODVDServices

#Enable the following line if you have regular/combo drive
#You might have to add IOCompactDiscServices/1 
#or IOCompactDiscServices/2 if you have multiple drives
#DEVICE=IOCompactDiscServices

DRIVER=generic-mmc

case $# in
  0)
    echo 'Usage: copycd filename' >&2 ; exit 1;;
  *)
  #extract the bsd disk number/name and volumename from the disktool listing
  disk=`disktool -l |grep Volumes |cut -d"," -f1|cut -d"(" -f2 |tr -d "'"` 
  volume=`disktool -l |grep Volumes |cut -d"," -f4|cut -d"(" -f2 |cut -d"'" -f2`
  echo "Unmounting disk:"$disk " volume:"$volume""
  disktool -u $disk
  echo "Creating disk image"
  sudo cdrdao read-cd --device $DEVICE --driver $DRIVER --read-raw $1.toc $1.bin
  echo "Created the disk image "$1.bin" and table of contents file "$1.toc"";;
esac  
-------- END copycd --------

--------  burncd ----------
#!/bin/bash 
#Jun 11, 2003 10:38 AM Shankar Chakkere 
#burn the AudioCD,VCD and DataCD

#Enable the following line if you have Superdrive
#You might have to add IODVDServices/1
#or IODVDServices/2 if you have multiple drives
DEVICE=IODVDServices

#Enable the following line if you have regular/combo drive
#You might have to add IOCompactDiscServices/1 
#or IOCompactDiscServices/2 if you have multiple drives
#DEVICE=IOCompactDiscServices

DRIVER=generic-mmc

case $# in
  0)
    echo 'Usage: burncd toc_file' >&2 ; exit 1;;
  *) 
  sudo cdrdao write --device $DEVICE --driver $DRIVER  $1;;
esac
-------- END burncd --------
A sample session:
[shankara@mymac ~/tmp/audio] % copycd besthits
Unmounting disk:"disk1 " volume:"Audio CD"
disk1 device will be unmounted ...
***Notifications Complete for type 1
***Responding yes to unmount - disk1
***Disk Unmounted('disk1')
Creating disk image
Password:
Cdrdao version 1.1.7 - (C) Andreas Mueller 
  SCSI interface library - (C) Joerg Schilling
  Paranoia DAE library - (C) Monty 
-----------
Reading toc and track data... 
-----------
Reading of toc and track data finished successfully.
Created the disk image "besthits.bin" and table of contents file "besthits.toc"
Now to burn the image ... when you insert a blank CD, the Finder will provide you with three options -- select "Ignore."
[shankara@mymac ~/tmp/audio] % burncd besthits.toc 

Comments (9)


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