Helo frndz,
I'm novice in shell scripting...I need ur frnd help to write a shell script for taking backups. This script should use cp command to take backups. Script can read the list of directories and destination directory from a file or ask user for this info interactively...

Example:
Only two options -i (for interactive run) and "-f file" (to read backup info from a file) are allowed. When an invalid option is entered, script displays a message in shown below:
$ a2backup -r
syntax: a2backup [ -i/ -f file]

$ a2backup -i
Welcome to the Interactive Backup utility
Enter the source directory [/home/maskara/sya710]:
Enter the destination directory: /home/backup
What type of backup do you want ( ncremental / [f]ull backup) :
Follow symbolic link (Y/N) [n]:
Directory backed up successfully...

Plz help me to do this...:( ...

Thnx

Recommended Answers

All 6 Replies

Use rsync. It already does this and has more robust command line options.

Sory dear SKnake, Thnx for ur reply...But I cant use any software...:( it's my assignment, have to do with writing a script...:( & also have to follow da above mentioned example...:( ...any other advise?? Do U know how to write this code?? plz help me...

Thnx again...

Why don't you share the code you have so far so we can see what needs to be done? The incremental backup is going to be a little bit of work...

Dear sknake,
I dun have code yet...I dun understand where I've to start!...:( I'm still trying to write this code...I dun understand how to initialize da OPTION value, so that da entered value (i.e, except '-i' or '-f') is invalid or not...I'm not good in programming man...:(

Thnx

I'll get you started with the user input. Here is the sample output:

sk@sk:~/tmp$ ./ba.sh
syntax: ./ba.sh [ -i/ -f file]
sk@sk:~/tmp$ ./ba.sh -i
Welcome to the Interactive Backup utility
Enter the source directory [/home/maskara/sya710]: /ab
Enter the destination directory [/home/backup]: /dc
/ab
/dc

Now the actual script:

#!/bin/bash

d_srcdir="/home/maskara/sya710"
d_dstdir="/home/backup"

if ([ "$1" == "-i" ]); then
  echo "Welcome to the Interactive Backup utility"
  echo -n "Enter the source directory [${d_srcdir}]: "
  read srcdir

  if ! test $srcdir; then
    srcdir=${d_srcdir}
  fi

  echo -n "Enter the destination directory [${d_dstdir}]: "
  read dstdir

  if ! test $dstdir; then
    dstdir=${d_dstdir}
  fi

  echo ${srcdir}
  echo ${dstdir}

else
  echo "syntax: ${0} [ -i/ -f file]"
fi

Dear sknake,

Sorry for long late reply...Thank you very much...It was really very helpful!...:D

Thnx again...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.