I just wrote this backup script:
#!/usr/bin/bash
# the number of days to do the backup for.
days=5;
# the files to backup.
location[0]='/opt/aDirectory/'
location[1]='/extra/anotherDirectory/'
# the location to copy the file to
copyLocation='/users/JoeBlow/Backup/backup-'$(date | tr ' ' '-')
# Log stuff
mkdir $copyLocation
echo "made backup for last $days">>$copyLocation/log
for loc in ${location[*]}
do
echo "made backup of $loc" >> $copyLocation/log
done
echo "Errors and Warnings from find and cp" >> $copyLocation/log
# preform the back up
for loc in ${location[*]}
do
for toBack in `find $loc \! -name '*.class' -mtime -$days \! -type d -print 2>> $copyLocation/log`
do
temp=${copyLocation}$(dirname $toBack)
mkdir -p $temp 2>> $copyLocation/log
cp $toBack $temp 2>> $copyLocation/log
done
done
But it is causing me grief.
When I was testing it I reached my disk quota. I thought no problem I will just rm -r
the directory that I created, clear up some space and try again. Nope. Doesn't work. I am getting this error;
% rm -r backup-Wed-Feb-10-16\:58\:59-EST-2010/
rm: Unable to remove directory backup-Wed-Feb-10-16:58:59-EST-2010//direcotry/something: File exists
....
Permissions problem right? Wrong.
I cd to the lowest place in that directory and there is one really big hidden file. So I rm
it. It allows be to delete it but places a new file in the dir with a slightly different name. What is gong on?
Two questions:
1 Is there something wrong with my backup script?
2 Why can't I delete that file?