944,107 Members | Top Members by Rank

Ad:
Nov 3rd, 2007
0

creating a backup file

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
keef12345 is offline Offline
2 posts
since Nov 2007
Nov 4th, 2007
0

Re: creating a backup file

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?
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Nov 4th, 2007
0

Re: creating a backup file

Click to Expand / Collapse  Quote originally posted by Duoas ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
keef12345 is offline Offline
2 posts
since Nov 2007
Nov 4th, 2007
0

Re: creating a backup file

/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.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Nov 4th, 2007
0

Re: creating a backup file

Alright. Here you go.

Tcl Syntax (Toggle Plain Text)
  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!
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007

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: time command
Next Thread in Shell Scripting Forum Timeline: how to use fastmail in shell script to send mail?





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


Follow us on Twitter


© 2011 DaniWeb® LLC