Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
|
12-20-2009, 08:41 AM
|
#16
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
right first things first thanks for all helps and hints this is what i have so far:
Code:
#!/bin/bash
clear
VALID_PATH=0
BACKUP_FILE=backup$(date +%Y%m%d).tgz
BACKUP_DIR=backup/
echo 1 Perform A Backup
echo 2 Restore From Backup
echo 3 Exit Program
read OPTION
case $OPTION in
"1") echo You picked 1
echo backup files
read SOURCE
while ["$VALID_PATH" -eq 0]
do
if [-d "$SOURCE"]; then
VALID_PATH=1
BACKUP_FILE="$BACKUP_DIR""$BACKUP_FILE"
echo all files
echo backed up to $BACKUP_FILE
else
echo this is invalid
echo please retry
read SOURCE
if [ "$SOURCE" == q ]; then
echo Goodbye!
exit 0
fi
fi
done
tar -czf $BACKUP_FILE $SOURCE
;;
"2") echo you chose 2
echo restore?
echo backup directory contents
ls $BACKUP_DIR
echo enter the name
read RESTORE_FILE
RESTORE_FILE="$BACKUP_DIR""$RESTORE_FILE"
until ["$VALID_PATH" !=0]
do
if [-f "$RESTORE_FILE"]; then
VALID_PATH=1
else
echo FAIL
echo Backup directory contents
echo
ls "$BACKUP_DIR"
echo
echo "q to quit!"
read RESTORE_FILE
if ["$RESTORE_FILE" ==q]; then
echo
echo goodbye!
exit 0
fi
RESTORE_FILE="$BACKUP_DIR""$RESTORE_FILE"
fi
done
echo
echo the file $RESTORE_FILE will be used to perform
echo
tar -xvf $RESTORE_FILE
;;
"3") echo goodbye
exit 0;;
esac
if ["$?" ==0]; then
if ["$OPTION"==1 -o "$OPTION" ==2]; then
echo
echo SUCCESS!
echo
echo the following files were backed to $BACKUP_FILE
echo
tar -tf $BACKUP_FILE
else
echo
echo SUCCESS
echo
echo restored
fi
else
echo failed
fi
now i get 3 options (put in quotes to makie it eadier to read soz if this wrong)
Quote:
1 Perform A Backup
2 Restore From Backup
3 Exit Program
1
You picked 1
backup files
ss1
backup: line 21: [0: command not found
tar: ss1: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors
backup: line 85: [2: command not found
failed
-bash-2.05b# ls
backup backup20091220.tgz pf ss wp
|
so what i have done is created backup dir in root,then 3 dirs in backup and files (wp1.txt ss1.xls pf1.jpg etc)in each dir. cd in backup dir and saved file into there and ran it. came up with above errors but when ls dir it shows a backup has been done and how do i get the backups into the correct folders.
thanks for any help
|
|
|
12-20-2009, 08:51 AM
|
#17
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Try putting spaces around all the elements of the [ ] tests, for example change
Code:
["$RESTORE_FILE" ==q]
to
Code:
[ "$RESTORE_FILE" == q ]
|
|
|
12-20-2009, 09:10 AM
|
#18
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
cheers corrected that and now get these errors
Quote:
1 Perform A Backup
2 Restore From Backup
3 Exit Program
1
You picked 1
backup files
ss
all files
backed up to backup/backup20091220.tgz
tar (child): backup/backup20091220.tgz: Cannot open: Not a directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
backup: line 85: [: 2: unary operator expected
failed
|
thanks
|
|
|
12-20-2009, 12:18 PM
|
#19
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
If you put "set -x" on the second line of your script then the script will echo to the screen every line that it executes: this may make it easier to debug.
The first error looks like maybe the directory "backup" does not exist: you need to get the script to check for that and make it if it is missing. Something like:
Code:
if [ ! -d "$BACKUP_DIR" ] ; then
mkdir "$BACKUP_DIR"
fi
The other thing is that in test you should use
Code:
if [ "$foo" = "$bar" ] ; then
instead of
Code:
if [ "$foo" == "$bar" ] ; then
(unless there is something in bash that lets == work)
Keep at it, you've almost got it done.
Cheers,
Evo2.
PS. If you put "set -x" on the second line of your script then the script will echo to the screen every line that it executes: this may make it easier to debug.
|
|
1 members found this post helpful.
|
12-20-2009, 12:25 PM
|
#20
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by marydoll
Code:
backup: line 85: [: 2: unary operator expected
|
-o does not mean logical OR; it is used to test if a shell option is on and must be followed by an optname. Use || for logical OR.
|
|
1 members found this post helpful.
|
12-20-2009, 01:52 PM
|
#21
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
cheers hopefully getting there now, backup dir is there but it seems to make backups outhwith the dirs i put in there wp ss pf, so when i do ls the backup shows in beside these dirs, is there any other code i have to type in to do this.
cheers
|
|
1 members found this post helpful.
|
12-20-2009, 02:30 PM
|
#22
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by evo2
The other thing is that in test you should use
Code:
if [ "$foo" = "$bar" ] ; then
instead of
Code:
if [ "$foo" == "$bar" ] ; then
(unless there is something in bash that lets == work)
|
There is  . Chapter and verse here where it says " string1 == string2 True if the strings are equal. ‘=’ may be used in place of ‘==’"
|
|
1 members found this post helpful.
|
12-20-2009, 02:34 PM
|
#23
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by marydoll
cheers hopefully getting there now, backup dir is there but it seems to make backups outhwith the dirs i put in there wp ss pf, so when i do ls the backup shows in beside these dirs, is there any other code i have to type in to do this.
cheers
|
That would be a lot easier to understand with "wp ss pf" translated into English. Maybe I'm being stupid but I can't even begin to guess what they mean. A brief ASCII art (like tree command output) showing the directories and files would help too. It's easier to read if you put it in code tags (that's a link to instructions or you may prefer to use "Advanced Edit" mode which has a # button for code tags).
|
|
|
12-20-2009, 02:45 PM
|
#24
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
sorry about that been a long day & night
wp ss pf are the directories and are short for wordprocessing spreadsheet and picture files and the backup file is showing in backup dir rather than dir ss wp or ss.
|
|
|
12-20-2009, 03:03 PM
|
#25
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by marydoll
sorry about that been a long day & night
wp ss pf are the directories and are short for wordprocessing spreadsheet and picture files and the backup file is showing in backup dir rather than dir ss wp or ss.
|
Hard to be confident without more information about what's going on but maybe
Code:
tar -czf $BACKUP_FILE $SOURCE
needs to be
Code:
tar -czf $BACKUP_DIR$BACKUP_FILE $SOURCE
|
|
|
12-20-2009, 03:31 PM
|
#26
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
changed code and still not putting backup in dirs, however received email from fellow student and he says it does not have to be working 100% as long as it backs up and restores so going to leave it at that, now have to do the report for it, thanks to all who replied and helped with input
cheers,but gonna take achance here does anyone know what the indexing retrieval method is.
cheers once again
|
|
|
12-20-2009, 04:18 PM
|
#27
|
LQ Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,476
|
Quote:
Originally Posted by marydoll
changed code and still not putting backup in dirs, however received email from fellow student and he says it does not have to be working 100% as long as it backs up and restores so going to leave it at that, now have to do the report for it, thanks to all who replied and helped with input
cheers,but gonna take achance here does anyone know what the indexing retrieval method is.
cheers once again
|
In what context??
Also, I disagree with "leave it at that". If you don't know what it's doing or how it's not working, you've still not really learned what's going on, or why, and have bodged something together, just to get by.
And if this is for college, don't they also check spelling, punctuation, grammar, etc.??
|
|
|
12-20-2009, 04:24 PM
|
#28
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by marydoll
changed code and still not putting backup in dirs, however received email from fellow student and he says it does not have to be working 100% as long as it backs up and restores so going to leave it at that, now have to do the report for it, thanks to all who replied and helped with input
cheers,but gonna take achance here does anyone know what the indexing retrieval method is.
cheers once again
|
Good luck with it!
Regards "the indexing retrieval method", better to start a new thread. Any context to help narrow it down? Maybe for searching texts? This might be some help -- the SMART system looks promising.
|
|
|
12-20-2009, 04:29 PM
|
#29
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by TB0ne
Also, I disagree with "leave it at that". If you don't know what it's doing or how it's not working, you've still not really learned what's going on, or why, and have bodged something together, just to get by.
|
I figure time constraints didn't allow much else -- which is a lesson in itself.
@marydoll: there are so many ways the script could be improved. If you're interested in this stuff, come back later and we'll not only work with you to get it working, we'll work to make it robust and a model of good practice. Would help if you can get a system that allows copy-and-paste into the thread, though.
|
|
|
12-20-2009, 05:11 PM
|
#30
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
Quote:
Also, I disagree with "leave it at that". If you don't know what it's doing or how it's not working, you've still not really learned what's going on, or why, and have bodged something together, just to get by
|
considering the only thing i could do 3 years ago was switch on a pc(just) i think i have come a long way, and where the only o/s i had heard of was windows and then you get hit with linux (not bad mouthing it by the way had to do a report on windows vs mac vs linux and it does have its advantages) it is a hell of a step up
i would love to get it working 100% but already overdue and have to start the report for it and that will take a good few hours as for spelling, grammar etc it has been a long few days trying to get as far as i did and if you take into account work, running around after kids, but again thanks to all those who have helped me with this
|
|
|
All times are GMT -5. The time now is 02:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|