•
•
•
•
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
![]() |
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
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.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
Alright. Here you go.
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
and the actual backup command:
This of course requires that your tar command understands the z option. If it doesn't (because it is ancient), just split the commands:
Enjoy!
Tcl Syntax (Toggle Plain Text)
#! /usr/bin/env wish # # userbackup.tcl # Backup a directory as a tar.gz file # # Error checking is minimal. # package require Tk proc main {} { set done false # (Don't show any windows except the dialogues) wm withdraw . while {!$done} { #------------------------------------------------------------------------- # Get the full path of the directory to backup set dirname [tk_chooseDirectory \ -initialdir ~ \ -title {Select the directory you wish to backup} \ -mustexist true] if {$dirname eq {}} { # tk_messageBox -icon info -title {} -message Cancelled. -type ok return } #------------------------------------------------------------------------- # Generate a default filename set basename [file tail $dirname] if {$basename eq {}} { tk_messageBox \ -icon info \ -title {} \ -message "You cannot backup '$dirname'" \ -type ok continue } # (tack on the date and time) set basename $basename.[clock format [clock seconds] -format %d-%m-%Y.%H%M] #------------------------------------------------------------------------- # Ask for the place to save the backup set filename [tk_getSaveFile \ -filetypes {{{Tar-gzipped files} {.tar.gz}}} \ -initialdir ~ \ -initialfile $basename \ -title {Select the backup filename}] if {$filename eq {}} { # tk_messageBox -icon info -title {} -message Cancelled. -type ok return } # (make sure the filename ends in either .tgz or .tar.gz) set ext [file extension $filename] if {($ext ne {.tgz}) && ($ext ne {.tar.gz})} { set filename $filename.tar.gz } # (make sure that the backup file isn't to be placed in any directory # being backed up) if {[string first \ [file normalize $dirname]/ \ [file normalize $filename]] == 0} { tk_messageBox \ -icon error \ -title {} \ -message {Your backup file cannot be in the directory being backed up (or any subdirectory).} \ -type ok continue } #--------------------------------------------------------------------- # Actually DO the backing up exec tar czf $filename $dirname #--------------------------------------------------------------------- # Ask if there are more folders to backup set ans [tk_messageBox \ -icon question \ -title {} \ -message {Do you wish to backup another directory?} \ -type yesno] set done [expr {$ans eq {no}}] } } main # 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
-initialdirand the actual backup command:
tar czf $filename $dirnameThis 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 $filenameEnjoy!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Creating an exe file (C++)
- Creating a setup file in VB 6.0 (Visual Basic 4 / 5 / 6)
- creating the text file that a form sends to email (HTML and CSS)
- Creating a Hosts File Pointers. . .Entry Level (Windows 9x / Me)
- Creating a .EXE file (Java)
- Please Help.... Space Missing from hard drive (Windows NT / 2000 / XP / 2003)
- Use Backup to Back Up Files and Folders on Your Computer in Windows XP (Windows tips 'n' tweaks)
- Format Backup Drives with NTFS (Windows tips 'n' tweaks)
Other Threads in the Shell Scripting Forum
- Previous Thread: time command
- Next Thread: how to use fastmail in shell script to send mail?



Linear Mode