954,228 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

creating a backup file

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

keef12345
Newbie Poster
2 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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?

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 
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

keef12345
Newbie Poster
2 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

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 yourtar 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!

Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You