Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
No matter what I do, it keeps coming up with errors, whenever I think I have fixed the error it seems to come up with something else and for some reason I cant see what I have done wrong. Error messages occur with fi, then, else.
Here is my script
#!/bin/bash -x
# Creating location of where Lorna Kennedy's backup file will be found #
Backup_Destination=LKBackup/Archive_$(date '+%d.%m.%y:%H:%M').tgz
Restore=LKBackup/
#Begin the while statement
while :
do
#User Menu selection
echo "**********************************************************************"
echo "*********** Backup and Restore ******************************"
echo "********************************************************************"
echo "*********** Chose from Option 1, 2 or 3 ******************"
echo "*******************************************************************"
echo "[1] Create a Backup File"
echo
echo "[2] Restore files and folders from a Backup"
echo
echo "[3] Exit System"
echo
echo
echo "----------- Enter your option [1-3]: ---------------------------"
echo
echo "==================================================================="
# Read Option which User has chosen
read Selection
read Selection
# Begin the case statement
case $Selection in
1) echo "Your selected Perform a Full Backup.";
# pause for 2 seconds
sleep 2
echo "Please enter carefully, the path of the files to backup";
# Read Option which User has chosen and error correct path and on
execution if it returns 0 then it is successful
read LOCATION
if [-d "$LOCATION"]; then
echo you are going to backup the files within "$LOCATION";
echo "the files or folders will be backed up to the location";
echo "folder named LKBackups";
# pause for 2 seconds
sleep 2
else
echo "error the file path is not valid or the files do not exist";
echo "please ensure that the file path entered is correct";
echo "please enter the file path or name again";
read LOCATION
# Execute backup of files
tar -cf $Backup_Destination $LOCATION
fi
# Check to make sure that the backup has completed correctly
if [$? == 0]; then
echo "$Backup_Destination" has been successful.;
# pause for 3 seconds
sleep 3
else
echo "There was an error with the files or folders so backup could not be
completed.";
# pause for 3 seconds
sleep 3
fi
;;
2) echo "You are about to restore files or folders from a backup":
# pause for 3 seconds
sleep 3
echo "any backups that are held within the backup folder will be listed
below";
ls "$Restore"
echo "select the file that you would like restored";
echo "enter the full path name carefully";
read RESTOREBACKUP
Restore_Destination="$Restore_Destination""$RESTOREBACKUP"
if [-f"$Restore_Destination"];
echo "Your files selected will now be restored";
# pause for 4 seconds
sleep 4
else
echo "There was an error with the file name";
echo "Please re-enter the file name";
read RESTOREBACKUP
Restore_Destination="$Restore_Destination""$RESTOREBACKUP"
fi
echo "The selected files will now be restored";
# pause for 4 seconds
sleep 4
tar -xf $Restore_Destination
if[$? == 0]; then
echo "$RESTOREBACKUP" backup has been successful;
# pause for 4 seconds
sleep 4
else
echo "There was a problem with your restore";
echo "Please check your file name is correct";
fi
;;
3) echo "GoodBye see you again soon $USER";
exit 1
;;
*) echo "Sorry you can only select from options 1, 2 or 3. Please try
again";
echo "press any key to continue";
read -n 1
;;
esac
done
I have no idea why it wont run properly, can anyone help please
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.