LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-30-2007, 09:02 AM   #1
soad789
LQ Newbie
 
Registered: Nov 2007
Location: Birmingham
Posts: 4

Rep: Reputation: 0
Backup Shell Script


Any ideas on a backup script please?

Last edited by soad789; 12-14-2007 at 03:32 AM.
 
Old 11-30-2007, 09:09 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Your wording makes this sound like a homework problem.

Backing up and immediately restoring doesn't make sense.

You will probably use the tar command to backup and restore. Refer to the man and info pages for examples.

You could easily use the argument(s) as the directory(ies) to backup and test what was entered was actually a directory. The backup could be performed with a single tar command, with the date appended to the directory name to allow multiple backups. Also read the info manual. There is a section on using a timestamp file to produce incremental backups.
 
Old 11-30-2007, 09:35 AM   #3
soad789
LQ Newbie
 
Registered: Nov 2007
Location: Birmingham
Posts: 4

Original Poster
Rep: Reputation: 0
Ok thanks, but can anyone give me an example script please?
 
Old 11-30-2007, 03:57 PM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Quote:
Originally Posted by soad789 View Post
Ok thanks, but can anyone give me an example script please?
Hmmm, that wasn't a denial.

Have you looked at the man page for tar?

Please post what you have so far within [ CODE ] [ /CODE ] tags (without spaces)

This will show us that you have attempted to do your homework and we can help point out any issues you are getting.

You will learn more from writing code that from copy typing other peoples work.
 
Old 12-07-2007, 04:11 AM   #5
soad789
LQ Newbie
 
Registered: Nov 2007
Location: Birmingham
Posts: 4

Original Poster
Rep: Reputation: 0
Ok well i have been working on it and so far i have created the menu system where a user can select to Backup a specified directory, Restore a specified directory or exit the program.

I just need some help with the actual scripts, can someone give me any ideas or examples please?

Here is what i have so far :


#!/bin/bash



function display_main_menu ()
{
clear

echo "Welcome to the backup program"
echo "***********"
echo "Menu"
echo "***********"

# List menu options

echo "Please choose from the following options: "
echo "A. Backup a directory"
echo "B. Restore a directory"
echo "C. Quit"
echo

exit="false"

while [ "$exit" = "false" ]
do

echo "***********"
echo -n "What is your choice? "
read choice

# See what the user has chosen to do

case "$choice" in
A|a ) function backup
exit="true"
;;
B|b ) function restore
exit="true"
;;
C|c ) exit
exit="true"
;;
* ) echo "Please enter valid choice"
;;
esac
done
}

function backup ()
{
clear

echo "This is the Backup Application "
echo "***********"

[BACKUP SCRIPT HERE]


esac
done
}


#*************************************


function restore ()
{
clear

echo "This is the Restore Application "
echo "***********"

[Restore SCRIPT HERE]


esac
done
}


#end

Last edited by soad789; 12-07-2007 at 04:15 AM.
 
Old 12-07-2007, 06:03 AM   #6
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
You are using exit as a variable but it is a reserved word in bash. Change that, I used EXIT. You have the Backup and Restore functions inside the main_menu function, I would suggest putting them outside that function. Change read choice to read -n1 choice and the user doesn't have to press <Enter>.

Beside that all you really need is to let the user input a directory and then make the tarball.

I'll show you making the tarball and let you figure out the restore part.

Code:
#!/bin/bash

function backup () {
clear
echo "Which directory do you want to Backup?"
echo "***********"
read BDIR
if [ ! -d "$BDIR" ];then
  echo "No such directory..."
  return
fi
# Uncomment following line to make script work
# tar cjvf $(basename $BDIR).tar.bz2 $BDIR
echo "tar cjvf $(basename $BDIR).tar.bz2 $BDIR"
}

#*************************************

function restore () {
clear
echo "This is the Restore Application "
echo "***********"

#[Restore SCRIPT HERE]
}
function display_main_menu () {
clear
echo "Welcome to the backup program"
echo "***********"
echo "Menu"
echo "***********"

# List menu options
echo "Please choose from the following options: "
echo "A. Backup a directory"
echo "B. Restore a directory"
echo "C. Quit"
echo
EXIT="false"

while [ "$EXIT" = "false" ]
  do
  echo "***********"
  echo -n "What is your choice? "
  read -n1 choice
  # See what the user has chosen to do
  case "$choice" in
    A|a )
    backup
    EXIT="true"
    ;;
    B|b )
    restore
    EXIT="true"
    ;;
    C|c )
    exit
    EXIT="true"
    ;;
    * )
    echo "Please enter valid choice"
    ;;
  esac
done
}

display_main_menu

Last edited by /bin/bash; 12-07-2007 at 06:05 AM. Reason: Fix formatting
 
Old 12-08-2007, 06:35 AM   #7
soad789
LQ Newbie
 
Registered: Nov 2007
Location: Birmingham
Posts: 4

Original Poster
Rep: Reputation: 0
Thank you very much for the help. Thats made things a lot clearer.
 
  


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
shell backup script help needed Quakeboy02 Linux - Software 4 04-26-2007 05:20 PM
Backup shell script: help me improve it? PatrickMay16 General 3 12-26-2006 06:55 PM
shell backup script xtremeclones Linux - Software 3 10-03-2006 02:13 PM
Shell Script for backup BBQ_Matt Linux - Software 7 06-30-2005 05:19 PM
writting a backup shell script yenonn Slackware 2 03-18-2004 07:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:31 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