creating a backup file

Reply

Join Date: Nov 2007
Posts: 2
Reputation: keef12345 is an unknown quantity at this point 
Solved Threads: 0
keef12345 keef12345 is offline Offline
Newbie Poster

creating a backup file

 
0
  #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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: creating a backup file

 
0
  #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 Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: keef12345 is an unknown quantity at this point 
Solved Threads: 0
keef12345 keef12345 is offline Offline
Newbie Poster

Re: creating a backup file

 
0
  #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 Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: creating a backup file

 
0
  #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 Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: creating a backup file

 
0
  #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:
Shell Scripting Syntax (Toggle Plain Text)
  1. if {[file extension $filename] eq {.tgz}} \
  2. then { set filename [file rootname $filename].tar } \
  3. else { set filename [file rootname $filename] }
  4. exec tar cf $filename $dirname
  5. exec gzip $filename

Enjoy!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC