LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 12-20-2009, 07:41 AM   #16
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0

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
 
Old 12-20-2009, 07:51 AM   #17
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Try putting spaces around all the elements of the [ ] tests, for example change
Code:
["$RESTORE_FILE" ==q]
to
Code:
[ "$RESTORE_FILE" == q ]
 
Old 12-20-2009, 08:10 AM   #18
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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
 
Old 12-20-2009, 11:18 AM   #19
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
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.
Old 12-20-2009, 11:25 AM   #20
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by marydoll View Post
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.
Old 12-20-2009, 12:52 PM   #21
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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.
Old 12-20-2009, 01:30 PM   #22
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by evo2 View Post
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.
Old 12-20-2009, 01:34 PM   #23
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by marydoll View Post
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).
 
Old 12-20-2009, 01:45 PM   #24
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 12-20-2009, 02:03 PM   #25
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by marydoll View Post
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
 
Old 12-20-2009, 02:31 PM   #26
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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
 
Old 12-20-2009, 03:18 PM   #27
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by marydoll View Post
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.??
 
Old 12-20-2009, 03:24 PM   #28
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by marydoll View Post
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.
 
Old 12-20-2009, 03:29 PM   #29
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by TB0ne View Post
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.
 
Old 12-20-2009, 04:11 PM   #30
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
Thumbs up

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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 08:52 AM
Backup Script Help cougar97536 Linux - Newbie 8 07-09-2009 04:09 PM
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 07:29 PM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM
Need a backup script enygma Linux - General 5 11-04-2004 03:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration