User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,587 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,607 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1133 | Replies: 4
Reply
Join Date: Nov 2007
Posts: 2
Reputation: keef12345 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
keef12345 keef12345 is offline Offline
Newbie Poster

Question creating a backup file

  #1  
Nov 3rd, 2007
Hi my family computer needs a backup script...

it needs to do the following tasks for us..
The script will ask the user which directory they wish to backup?
the backup will 'ask' the user for the full pathname of the backup to create

also i need the script to ask the users in my family if they need to do another backup?
and if the user enters n=no.

Thankyou guys I have a backup script i wrote but i need these extra features and i cant see how to write the code for them.

Thanks heaps
Last edited by keef12345 : Nov 3rd, 2007 at 6:46 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: creating a backup file

  #2  
Nov 4th, 2007
Hey there, I've been playing around with a WSH script that could do it for you. However, I need to know, are you using XP?
Reply With Quote  
Join Date: Nov 2007
Posts: 2
Reputation: keef12345 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
keef12345 keef12345 is offline Offline
Newbie Poster

News Re: creating a backup file

  #3  
Nov 4th, 2007
Originally Posted by Duoas View Post
Hey there, I've been playing around with a WSH script that could do it for you. However, I need to know, are you using XP?


ill be using this code on a fedora machine

thankyou heaps i need some code help bad
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: creating a backup file

  #4  
Nov 4th, 2007
/me reads first post yet again

Hmm. I don't know why I thought you were using windows.

In any case, this makes it a bit easier. I'll just use Tcl/Tk. Give me a day or two and I'll give you a you nice GUI script.
Last edited by Duoas : Nov 4th, 2007 at 7:11 am.
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: creating a backup file

  #5  
Nov 4th, 2007
Alright. Here you go.

  1. #! /usr/bin/env wish
  2. #
  3. # userbackup.tcl
  4. # Backup a directory as a tar.gz file
  5. #
  6. # Error checking is minimal.
  7. #
  8. package require Tk
  9.  
  10. proc main {} {
  11. set done false
  12.  
  13. # (Don't show any windows except the dialogues)
  14. wm withdraw .
  15.  
  16. while {!$done} {
  17.  
  18. #-------------------------------------------------------------------------
  19. # Get the full path of the directory to backup
  20. set dirname [tk_chooseDirectory \
  21. -initialdir ~ \
  22. -title {Select the directory you wish to backup} \
  23. -mustexist true]
  24. if {$dirname eq {}} {
  25. # tk_messageBox -icon info -title {} -message Cancelled. -type ok
  26. return
  27. }
  28.  
  29. #-------------------------------------------------------------------------
  30. # Generate a default filename
  31. set basename [file tail $dirname]
  32. if {$basename eq {}} {
  33. tk_messageBox \
  34. -icon info \
  35. -title {} \
  36. -message "You cannot backup '$dirname'" \
  37. -type ok
  38. continue
  39. }
  40.  
  41. # (tack on the date and time)
  42. set basename $basename.[clock format [clock seconds] -format %d-%m-%Y.%H%M]
  43.  
  44. #-------------------------------------------------------------------------
  45. # Ask for the place to save the backup
  46. set filename [tk_getSaveFile \
  47. -filetypes {{{Tar-gzipped files} {.tar.gz}}} \
  48. -initialdir ~ \
  49. -initialfile $basename \
  50. -title {Select the backup filename}]
  51. if {$filename eq {}} {
  52. # tk_messageBox -icon info -title {} -message Cancelled. -type ok
  53. return
  54. }
  55.  
  56. # (make sure the filename ends in either .tgz or .tar.gz)
  57. set ext [file extension $filename]
  58. if {($ext ne {.tgz}) && ($ext ne {.tar.gz})} {
  59. set filename $filename.tar.gz
  60. }
  61.  
  62. # (make sure that the backup file isn't to be placed in any directory
  63. # being backed up)
  64. if {[string first \
  65. [file normalize $dirname]/ \
  66. [file normalize $filename]] == 0} {
  67. tk_messageBox \
  68. -icon error \
  69. -title {} \
  70. -message {Your backup file cannot be in the directory being backed up (or any subdirectory).} \
  71. -type ok
  72. continue
  73. }
  74.  
  75. #---------------------------------------------------------------------
  76. # Actually DO the backing up
  77. exec tar czf $filename $dirname
  78.  
  79. #---------------------------------------------------------------------
  80. # Ask if there are more folders to backup
  81. set ans [tk_messageBox \
  82. -icon question \
  83. -title {} \
  84. -message {Do you wish to backup another directory?} \
  85. -type yesno]
  86. set done [expr {$ans eq {no}}]
  87. }
  88. }
  89.  
  90. main
  91.  
  92. # end

This should work on any platform that has Tcl/Tk installed. Since you are using Fedora linux I forsee no problems.

Tcl code is pretty simple, so you can change things as you see fit. The stuff of greatest interest are where you see
-initialdir
and the actual backup command:
tar czf $filename $dirname
This of course requires that your tar command understands the z option. If it doesn't (because it is ancient), just split the commands:
if {[file extension $filename] eq {.tgz}} \
  then { set filename [file rootname $filename].tar } \
  else { set filename [file rootname $filename] }
exec tar cf $filename $dirname
exec gzip $filename

Enjoy!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 6:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC