Issue with my backup script
I wrote a fairly simple backup script for my Linux machine in bash. Essentially it is a recursive script that looks at all the files in the directory, sees if they exist in the backup, then sees if they are newer than the backup, and then backs them up if necessary. So, here is the one problem I can't yet solve...
When the script is called it takes from two to an infinite number of arguments. The first is the backup destination, and the following arguments are sources. It goes through this list with the $@ variable in a for loop. When an argument is a directory, it calls itself with the appropriately altered destination directory and a /* added on to the source directory. So, for example, if I wanted to backup /source to /backup and one of the arguments was a subdirectory /source/sub then this is how it would work... Code:
# First I call the script Code:
if [ -e "$arg" ] ; then Thanks very much in advance. :) |
I don't want to discourage your scripting efforts,
but why don't you use this rsync backup-script and build up on that? Cheers, Tink |
I appreciate the suggestion, but this is largely just a learning tool for me. I wouldn't feel like it was a success if I couldn't figure this out. :/
|
In this case :)
Have a look at Druuna's fabulous support http://www.linuxquestions.org/questi...pace+file+name Cheers, Tink |
I read over the thread, but I didn't see anything that solved my problem. The issue is that if the argument in the command line (in this case the return value of the wildcard *) has two spaces in it, when testing that the file exists (which is necessary in case the file name was typed explicitly by the user, and it was inaccurate), it ends up evaluating to false when the file does exist.
Sorry for any confusion. I realize this is probably not the best description, but it's the best I can do. :/ |
Well, you'll basically need to put the $VARIABLE
that holds the value of the file/direcotry name into Quotes ("$VARIABLE") so the string with spaces gets treated like ONE value... That said, spaces in file-names are a MS abomination and shouldn't be used ;) Cheers, Tink |
I found the solution. I had a line in the script to remove trailing slashes from any directories, and it was cutting the second space out of the file names. The line was something like this...
Code:
echo $arg | sed 's/\/$//' Code:
echo "$arg" | sed 's/\/$//' EDIT: (Post Script, actually) I'm backing up files on our shared network drive. That means that my wife has files on the drive. That means I'm lucky there aren't files with slashes, asterisks, tabs, etc in them. I have to assume the worst when dealing with her file names. ;) |
Pleasure mate :}
And you should educate your wife ;} Cheers, Tink P.S.: The downside of people not knowing anything about underlying file-systems is utter stupidity when it comes to naming conventions of files ;) I had that guy ask me why the hell he couldn't use that back-slash in his filename in Word :D |
All times are GMT -5. The time now is 03:58 AM. |