ikeurb
June 10th, 2010, 10:46 PM
Okay, needless to say I don't have much experience with Linux or shell scripting.
For practice, I am writing a script that will prompt the user for a path to backup from then a path to backup to. Sounds easy enough, but I'd like to do some error checking and prevention too.
This first think I do is ask the user for folder to backup.
echo "Welcome $USER!, what would you like to backup? "
read BACK_UP_FROM
then I ask the user for the destination to backup to.
echo "Welcome $USER!, what is the destination path to backup to?"
read BACK_UP_FROM
I then check to see if the destination directory exists, if not I create it.
Next I create the filename...
FILENAME=backup-$CURRENT_TIME.tar
and start the backup process.
tar cf $BACK_UP_TO$FILENAME $BACK_UP_FROM
My questions are:
1.) How do I validate that source path to backup is valid or not?
2.) How can append the filename with a suffix if the backup file already exists. i.e. If backup-20100610 already exists, how can I append the filename to backup2-20100610?
3.) I also would like to avoid backing up the /. hidden files and folders. Advice?
Thanks for helping me learn the ways of shell scripting.
For practice, I am writing a script that will prompt the user for a path to backup from then a path to backup to. Sounds easy enough, but I'd like to do some error checking and prevention too.
This first think I do is ask the user for folder to backup.
echo "Welcome $USER!, what would you like to backup? "
read BACK_UP_FROM
then I ask the user for the destination to backup to.
echo "Welcome $USER!, what is the destination path to backup to?"
read BACK_UP_FROM
I then check to see if the destination directory exists, if not I create it.
Next I create the filename...
FILENAME=backup-$CURRENT_TIME.tar
and start the backup process.
tar cf $BACK_UP_TO$FILENAME $BACK_UP_FROM
My questions are:
1.) How do I validate that source path to backup is valid or not?
2.) How can append the filename with a suffix if the backup file already exists. i.e. If backup-20100610 already exists, how can I append the filename to backup2-20100610?
3.) I also would like to avoid backing up the /. hidden files and folders. Advice?
Thanks for helping me learn the ways of shell scripting.