943,576 Members | Top Members by Rank

Ad:
Aug 21st, 2009
0

Need help to write a backup script...

Expand Post »
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 ( [i]ncremental / [f]ull backup) [i]:
Follow symbolic link (Y/N) [n]:
Directory backed up successfully...

Plz help me to do this... ...

Thnx
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
baula is offline Offline
7 posts
since Jul 2009
Aug 21st, 2009
0

Re: Need help to write a backup script...

Use rsync. It already does this and has more robust command line options.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Aug 21st, 2009
0

Re: Need help to write a backup script...

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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
baula is offline Offline
7 posts
since Jul 2009
Aug 21st, 2009
0

Re: Need help to write a backup script...

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...
Last edited by sknake; Aug 21st, 2009 at 4:45 pm.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Aug 21st, 2009
0

Re: Need help to write a backup script...

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
baula is offline Offline
7 posts
since Jul 2009
Aug 21st, 2009
0

Re: Need help to write a backup script...

I'll get you started with the user input. Here is the sample output:
bash Syntax (Toggle Plain Text)
  1. sk@sk:~/tmp$ ./ba.sh
  2. syntax: ./ba.sh [ -i/ -f file]
  3. sk@sk:~/tmp$ ./ba.sh -i
  4. Welcome to the Interactive Backup utility
  5. Enter the source directory [/home/maskara/sya710]: /ab
  6. Enter the destination directory [/home/backup]: /dc
  7. /ab
  8. /dc

Now the actual script:
bash Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2.  
  3. d_srcdir="/home/maskara/sya710"
  4. d_dstdir="/home/backup"
  5.  
  6. if ([ "$1" == "-i" ]); then
  7. echo "Welcome to the Interactive Backup utility"
  8. echo -n "Enter the source directory [${d_srcdir}]: "
  9. read srcdir
  10.  
  11. if ! test $srcdir; then
  12. srcdir=${d_srcdir}
  13. fi
  14.  
  15. echo -n "Enter the destination directory [${d_dstdir}]: "
  16. read dstdir
  17.  
  18. if ! test $dstdir; then
  19. dstdir=${d_dstdir}
  20. fi
  21.  
  22. echo ${srcdir}
  23. echo ${dstdir}
  24.  
  25. else
  26. echo "syntax: ${0} [ -i/ -f file]"
  27. fi
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Sep 3rd, 2009
0

Re: Need help to write a backup script...

Dear sknake,

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

Thnx again...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
baula is offline Offline
7 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: How can i display time 5mins ago on Solaris 10
Next Thread in Shell Scripting Forum Timeline: Very new to this and would appreciate any help possible.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC