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

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?

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

/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.

Alright. Here you go.

#! /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 -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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.