views:

57

answers:

3

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?

+1  A: 

In some environments rm is aliased to something that supports undeletion, to try to save users from themselves. I wonder if that could be the case? Could you repeat the experiment with both

/bin/rm -r backup-Wed-Feb-10-16\:58\:59-EST-2010/

or possibly

/bin/rm -rf backup-Wed-Feb-10-16\:58\:59-EST-2010/

and let us know the results?

Norman Ramsey
`/bin/rm` does not exist. My rm is in /usr/bin/rm,
sixtyfootersdude
OK, then try `/usr/bin/rm`
Norman Ramsey
+1  A: 

What is the filesystem type for that directory? I see references to locale settings and ntfs-3g leading to the "file exists" error (ntfs-3g cannot display the file properly, but it is still there).

Justin Smith
+1  A: 

Without more information, I'll go out on a limb: your script is correct, if a little dangerous. It is trying to copy many files into your backup area, but gets stuck because there isn't enough space. When you delete a big file, you free up enough space for it to copy in some more files. It can copy them in as fast as you can delete them.

I suggest you kill the process, clear out the backup area, and put a space check in the script.

Beta
pretty sure that it is not running anymore. How could I verify this?
sixtyfootersdude
Actually you are correct. I have no idea how it began running in the background (feedback?). I did not put it into the background, but when I run ps, there were two instances of the script running. Killed them and then was able to delete the file. I just cannot figure out how the script snuck into the background...
sixtyfootersdude
As to how it got into the background (if that's really where it was-- did you try fg?) I have no idea, but I'm learning to put safeguards on powerful scripts and watch for signs of runaway.
Beta