Question : bash backup script help needed!!

Hi, I need help with bash backup script, I was required to write a backup linux bash script.
The script should ask the user a directory to backup. It should then go and search the users home directory for existence of that directory. If it is found it should tar/gzip all the files and directories in that directory preserving the directory structure in a file named with the directory name and an appended integer. It should store the tarred file in a directory called backups in the home directory. Each time the script is run, it should make a tar file with the directory name and an appended, incremented digit.
Eg. Filenames could be myfiles1.tar.gz, myfiles2.tar.gz, mypictures4.tat.gz
If multiple occurrences of the directory are found then the script should output all the occurrences of the directories and ask the user the particular directory that needs to be backed up. Read the in the new particular directory that needs to be backed up and back it up as above if it is valid else redisplay the directories. Also allow a choice x to be typed to exit the menu.
If the directory does not exist the exit with an appropriate message
 
I did following code, and I don't know what I didi wrong, it is giving me wrong message,
any new code would be helpful, I maybe doing it wrong.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
#!/bin/bash
find . -type d
dateTime=$(/bin/date +"%Y_%h_%d_%H_%M_%S")
read -p "Please press y to continue with backup or press x to exit this menu:" option1
if [ "$option1" == "y" ];then
        echo "You have selected 'y', starting backup now"
        read -p "Please enter a directory name to backup:" dir1
        if [ -d $dir1 ];then
                echo Directory found, backing up now
                tar cfz $dir1.$dateTime.tar.gz $dir1
                echo "Backup for directory $dir1 was successful"
                read -p "would you like to continue or exit now? press y to continue or x to exit:" option2
                if [ "$option2" == "y" ];then
                        echo "You have selected 'y', starting backup now"
                        read -p "Please enter a directory name to backup:" dir2
                        if [ -d $dir2 ];then
                                echo Directory found, backing up now
                                tar cfz $dir2.$dateTime.tar.gz $dir2
                                echo "Backup for directory $dir2 was successful, exiting now"
                                exit
                        else
                                echo Directory not found, exiting now
                                exit
                        fi
  
                fi
                if [ "$option2" == "x" ];then
                        echo you have selected x to exit, exiting now
                        exit
                fi
        else
                echo Directory not found
                read -p "Would you like to try again or exit? Press Y to continue or X to exit:" option3
                if [ "$option3" == "y" ];then
                        echo "You have selected 'Y', starting backup now
                        read -p "Please enter a directory name to backup:" dir3
                        if [ -d $dir3 ];then
                                echo Directory found, backing up now
                                tar cfz $dir3.$dateTime.tar.gz $dir3
                                echo "Backup for directory $dir3 was successful, exiting now"
                                exit
                        else
                                echo Directory not found, exiting now
                                exit
                        fi
                fi
                if [ "$option3" == "x" ];then
                        echo you selected x, exiting now
                        exit
                fi
        fi
fi
if [ "$option1" == "x" ];then
        echo you selected x, exiting now
fi
if [ "$option1" != "y" ] || [ "$option1" != "x" ];then
        echo I was expecting y or x , I didn't get what you entered, bye
        exit
fi
Open in New Window Select All

Answer : bash backup script help needed!!

Please see this one:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
#!/bin/bash
find . -type d
dateTime=$(/bin/date +"%Y_%h_%d_%H_%M_%S")
read -p "Please press y to continue with backup or press x to exit this menu:" option1
if [ "$option1" == "y" ];then
        echo "You have selected 'y', starting backup now"
        read -p "Please enter a directory name to backup:" dir1
        if [ -d $dir1 ];then
                echo Directory found, backing up now
                tar cfz $dir1.$dateTime.tar.gz $dir1
                echo "Backup for directory $dir1 was successful"
                read -p "would you like to continue or exit now? press y to continue or x to exit:" option2
                if [ "$option2" == "y" ];then
                        echo "You have selected 'y', starting backup now"
                        read -p "Please enter a directory name to backup:" dir2
                        if [ -d $dir2 ];then
                                echo Directory found, backing up now
                                tar cfz $dir2.$dateTime.tar.gz $dir2
                                echo "Backup for directory $dir2 was successful, exiting now"
                                exit
                        else
                                echo Directory not found, exiting now
                                exit
                        fi
  
                fi
                if [ "$option2" == "x" ];then
                        echo you have selected x to exit, exiting now
                        exit
                fi
        else
                echo Directory not found
                read -p "Would you like to try again or exit? Press Y to continue or X to exit:" option3
                if [ "$option3" == "y" ];then
                        echo "You have selected 'Y', starting backup now"
                        read -p "Please enter a directory name to backup:" dir3
                        if [ -d $dir3 ];then
                                echo Directory found, backing up now
                                tar cfz $dir3.$dateTime.tar.gz $dir3
                                echo "Backup for directory $dir3 was successful, exiting now"
                                exit
                        else
                                echo Directory not found, exiting now
                                exit
                        fi
                fi
                if [ "$option3" == "x" ];then
                        echo you selected x, exiting now
                        exit
                fi
        fi
fi
if [ "$option1" == "x" ];then
        echo you selected x, exiting now
fi
 
if [ "$option1" != "y" -a "$option1" != "x" ];then
        echo "I was expecting y or x, I didn't get what you entered, bye"
        exit
fi
Open in New Window Select All
Random Solutions  
 
programming4us programming4us