Why don't you just use rsync? This is a significant undertaking when the wheel has already been invented.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Yeah .. look at the rsync source for ideas :)
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Ok well build a file index of your source directories and destination directories. Then build a list of source/dest files that do not exist in either folders and delete/add them as necessary. For files that do exist in both directories you should use an md5sum and filesize check depending on how careful you want to be. Collision rates are very low (unless malicious and intentional) for md5sums so you could probably get away with just do that.
You could use ls and parse the columns, or use du or stat :
root@svn:/root/backup# du -b backup.sh | sed 's/\([0-9]*\)\(.*\)/\1/'
4252
Just because the size is the same doesn't mean that it has not changed so also compare the md5 stamp:
root@svn:/root/backup# md5sum backup.sh | sed 's/\([a-Z0-9]*\)\(.*\)/\1/'
241cca25e509409c1fbd6f1d46ec94e6
Now just automate all of that and you're good to go!
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
>>md5sum would actually show me the md5 of backup.sh right? Not the actual files in the backed up file/folder/etc. And why would I cut off those chars if md5 includes letters and numbers?
The expression I gave for the md5 didn't cut off anything, it took the entire hash. Just like du you will need to run md5sum on every file to get the file size & check sum.
As far as your concept for builing the directories -- yes, that is how you would go about it. However ls prints out a lot of crap you don't need for this so you would be better off using find /src/dir -type d to make that directories with mkdir -p and then use find /src/dir -type f to get the files.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
.... you have a long road ahead of you :)
Take your pick
sk@sk:~$ pwd
/home/wheel/sk
sk@sk:~$ echo ${PWD}
/home/wheel/sk
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
you shouldn't be cd'ing in a shell script to do backups in my opinion so that should be irrelevant.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Well pwd gives you the current directory. In a shell script if you're not using 'cd' then the result of 'pwd' would never change -- thus raising the question of why use it?
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735