iTunes Backup Shell Script

I’m starting over with my iTunes library. During this process, I needed to backup the existing library based on file type. Basically, I only wanted to move the non-DRM files back in. This hastily written script copies the iTunes library content to directories based on file type. So you end up with Backup/m4a, Backup/mp3, Backup/m4p, etc. (One caveat is if two songs have the exact same file type, track number and title. One will get overwritten.)

#!/bin/sh

# this script backs up your iTunes content into directories based on file type
# use at your own risk

# where do you want the archive?
DESTDIR="/Volumes/Backup/iTunes"
ITUNESDIR="/Users/fburns/Music"

# file extensions we might find (this is what was in my library)
# .aa    audio books
# .ipa   apps
# .m4p   protected content
# .m4a   purchased or imported AAC
# .mp3   old mp3's
# .mp4   mpeg4 videos
# .m4r   ring tones
# .m4v   videos
# .pdf   pdf's

EXTENSIONS="aa
ipa
m4p
m4a
mp3
mp4
m4r
m4v
pdf"

for EXT in $EXTENSIONS
do
  mkdir -p "$DESTDIR/$EXT"
  echo "Copying... to $DESTDIR/$EXT/"
  find $ITUNESDIR -name "*.$EXT" -print -exec cp {} "$DESTDIR/$EXT/" \;
done