All pastes #897938 Raw Edit

Someone

public text v1 · immutable
·published 2008-02-09 23:01 UTC
rendered paste body
 find $directory -name $filename -type f  | xargs > tempfile.txt #store filepaths in file
        if (-z tempfile.txt) then #check if the tempfile is empty (no files need backup)
            foreach string (`cat tempfile.txt`) #make backup for each file 
                printf "`n------------------------Checking up $string----------------------------\n"
                if (!(-e "$string.bak")) then #If no backup for a file exists - make backup
                    printf "\n$string.bak does not exist! Making a backup..."
                    cp $string $string.bak
                    printf "DONE\n"
                    ls -l `pwd`/$string.bak
                else
                    printf "\n$string.bak exists! Checking if there is any difference with the original..."
                    diff $string $string.bak > differences.txt
                    printf "DONE\n"
                    if (-z differences.txt) then
                        printf "Thare are no differences between the backup and the original. No copy required.\n"
                    else
                        printf "Differences detected. Making a copy of the backup with today's date attached..."
                        cp $string.bak $string.bak.`date +%Y%m%d`
                        printf "DONE\n"
                        ls -l `pwd`/$string.bak.`date +%Y%m%d`
                    endif
                    rm -rf differences.txt
                endif
                printf "\n------------------------Backed up $string----------------------------"
            end
         else