I've written my first bash script for backing up my music album by album onto an external FAT32 drive.
Code:
#!/bin/bash
# Music collection backup script
# Each album folder goes into one tar.gz file in target location (because of 4gb limit in fat32)
# Each album added is appended to album_list - simple text file in target dir
# Gzipping is a waste of time. The gain over mp3 compression is negilible
backup_dir=/media/IOMEGA_HDD/linux_backup/music_collection
music_dir=/home/paul/music/collection
album_list=/$backup_dir/album_list
touch $album_list
cd $music_dir
for album in *
do
if [ -f $backup_dir/"$album" ]
then
echo $album is already backed up
else
tar -cf $backup_dir/"$album" "$album"
echo $album >> $album_list
It generally works as expected even with filenames full of spaces. My problem lies with albums with ':' characters in the title:
Which give the following error:
Code:
tar: /media/IOMEGA_HDD/linux_backup/music_collection/Mogwai-Government Commissions\: BBC Sessions 1996-2003: Cannot open: Invalid argument
It's nothing to do with the file length. I wonder if enclosing in "" doesn't allow you to escape two non-standard characters in a row?
Any ideas? I'd rather not change all my filenames, because I'd rather a robust script that works with a variety of stuff.