On Tue, Dec 22, 2009 at 3:09 AM, Dale <rdalek1...@gmail.com> wrote: > Neil Walker wrote: >> >> Dale wrote: >> >>> >>> Me again. I'm thinking about writing a bash script that backs up my >>> /home directory. >>> >> >> I use a simple rsync cron job to backup entire servers every hour. Does >> the job for me. ;) >> >> >> Be lucky, >> >> Neil >> http://www.the-workathome.com >> >> > > But I wouldn't learn how to write a script that way. I got to start > somewhere. This is a good place. > > Dale > > :-) :-) >
Now I got your point. I would think on something like this (untested): The command line would be BackupScriptName FromDirectory ToDirectory #! /bin/bash FROM=$1 TO=$2 cd $FROM for i in * .??* do if [[ -d "$i" ]] # is it a directory? then # yes, it is a directory if [[ -e "$TO/$i" ]] && [[ -d "$TO/$i" ]] then # on the TO side, the name exists # and it is a directory cd "$i" # just to show something pwd # calls recursively this same script $0 "$FROM/$i" "$TO/$i" cd .. else # didn't existed yet on the TO side, # so copy everything cp -a $FROM/$i $TO/$i fi else # it is a file, not a directory if [[ -e "$TO/$i" ]] then # the file already exists # do something to compare the files, like: # gets size from "ls" result SIZE1=`ls -l "$i" | cut -d" " -f5` SIZE2=`ls -l "TO/$i" | cut -d" " -f5 if (( $SIZE1!=$SIZE2 )) then # size is different, so copy the file cp -a "$FROM/$i" "$TO/$i" else # more tests for differences other # than size, like date/time # or even MD5SUM fi else # file doesn't exist at the "TO" side cp -a "$FROM/$i" "$TO/$i" fi fi done Hope this helps Francisco -- "If you have an apple and I have an apple and we exchange apples then you and I will still each have one apple. But if you have an idea and I have one idea and we exchange these ideas, then each of us will have two ideas." - George Bernard Shaw