home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / samba-1.9.18p7.tar.gz / samba-1.9.18p7.tar / samba-1.9.18p7 / source / smbtar < prev    next >
Text File  |  1997-10-07  |  4KB  |  141 lines

  1. #!/bin/sh
  2. #
  3. # smbtar script - front end to smbclient
  4. #
  5. # Authors: Martin.Kraemer <Martin.Kraemer@mch.sni.de>
  6. #          and Ricky Poulten (ricky@logcam.co.uk)
  7. #
  8. # (May need to change shell to ksh for HPUX or OSF for better getopts)
  9.  
  10. case $0 in
  11.     # when called by absolute path, assume smbclient is in the same directory
  12.     /*)
  13.     SMBCLIENT="`dirname $0`/smbclient";;
  14.     *)  # you may need to edit this to show where your smbclient is
  15.     SMBCLIENT="smbclient";;
  16. esac
  17.  
  18. # These are the default values. You could fill them in if you know what
  19. # you're doing, but beware: better not store a plain text password!
  20. server=""
  21. service="backup"            # Default: a service called "backup"
  22. password=""
  23. username=$LOGNAME           # Default: same user name as in *nix
  24. verbose="2>/dev/null"        # Default: no echo to stdout
  25. log="-d 2"
  26. newer=""
  27. blocksize=""
  28. tarcmd="c"
  29. tarargs=""
  30. cdcmd="\\"
  31. tapefile=${TAPE-tar.out}
  32.  
  33. Usage(){
  34.     ex=$1
  35.     shift
  36. echo >&2 "Usage: `basename $0` [<options>] [<include/exclude files>]
  37. Function: backup/restore a Windows PC directories to a local tape file
  38. Options:         (Description)                 (Default)
  39.   -r             Restore from tape file to PC  Save from PC to tapefile
  40.   -i             Incremental mode              Full backup mode
  41.   -v             Verbose mode: echo command    Don't echo anything
  42.   -s <server>    Specify PC Server             $server
  43.   -p <password>  Specify PC Password           $password
  44.   -x <share>     Specify PC Share              $service
  45.   -X             Exclude mode                  Include
  46.   -N <newer>     File for date comparison      `set -- $newer; echo $2`
  47.   -b <blocksize> Specify tape's blocksize      `set -- $blocksize; echo $2`
  48.   -d <dir>       Specify a directory in share  $cdcmd
  49.   -l <log>       Specify a Samba Log Level     `set -- $log; echo $2`
  50.   -u <user>      Specify User Name             $username
  51.   -t <tape>      Specify Tape device           $tapefile
  52. "
  53.   echo >&2 "$@"
  54.   exit $ex
  55. }
  56.  
  57. while getopts rivl:b:d:N:s:p:x:u:Xt: c; do
  58.   case $c in
  59.    r) # [r]estore to Windows (instead of the default "Save from Windows")
  60.       tarcmd="x"
  61.       ;;
  62.    i) # [i]ncremental
  63.       tarargs=${tarargs}g
  64.       ;;
  65.    l) # specify [l]og file
  66.       log="-d $OPTARG"
  67.       case "$OPTARG" in
  68.     [0-9]*) ;;
  69.     *)      echo >&2 "$0: Error, log level not numeric: -l $OPTARG"
  70.         exit 1
  71.       esac
  72.       ;;
  73.    d) # specify [d]irectory to change to in server's share
  74.       cdcmd="$OPTARG"
  75.       ;;
  76.    N) # compare with a file, test if [n]ewer
  77.       if [ -f $OPTARG ]; then
  78.     newer=$OPTARG
  79.         tarargs=${tarargs}N
  80.       else
  81.     echo >&2 $0: Warning, $OPTARG not found
  82.       fi
  83.       ;;
  84.    X) # Add exclude flag
  85.       tarargs=${tarargs}X
  86.       ;;
  87.    s) # specify [s]erver's share to connect to - this MUST be given.
  88.       server="$OPTARG"
  89.       ;;
  90.    b) # specify [b]locksize
  91.       blocksize="$OPTARG"
  92.       case "$OPTARG" in
  93.     [0-9]*) ;;
  94.     *)      echo >&2 "$0: Error, block size not numeric: -b $OPTARG"
  95.         exit 1
  96.       esac
  97.       tarargs=${tarargs}b
  98.       ;;
  99.    p) # specify [p]assword to use
  100.       password="$OPTARG"
  101.       ;;
  102.    x) # specify windows [s]hare to use
  103.       service="$OPTARG"
  104.       ;;
  105.    t) # specify [t]apefile on local host
  106.       tapefile="$OPTARG"
  107.       ;;
  108.    u) # specify [u]sername for connection
  109.       username="$OPTARG"
  110.       ;;
  111.    v) # be [v]erbose and display what's going on
  112.       verbose=""
  113.       ;;
  114.    '?') # any other switch
  115.        Usage 2 "Invalid switch specified - abort."
  116.       ;;
  117.   esac
  118. done
  119.  
  120. shift `expr $OPTIND - 1`
  121.  
  122. if [ "$server" = "" ] || [ "$service" = "" ]; then
  123.   Usage 1 "No server or no service specified - abort."
  124. fi
  125.  
  126. # if the -v switch is set, the echo the current parameters
  127. if [ -z "$verbose" ]; then
  128.       echo "server    is $server"
  129. #     echo "share     is $service"
  130.       echo "share     is $service\\$cdcmd"
  131.       echo "tar args  is $tarargs"
  132. #     echo "password  is $password"  # passwords should never be sent to screen
  133.       echo "tape      is $tapefile"
  134.       echo "blocksize is $blocksize"
  135. fi
  136.  
  137. eval $SMBCLIENT "'\\\\$server\\$service'" "'$password'" -U "'$username'" \
  138. -E -N $log -D "'$cdcmd'" \
  139. -T${tarcmd}${tarargs} $blocksize $newer $tapefile $* $verbose
  140.  
  141.