From: edp@MATH.zko.dec.com (Eric Postpischil)
Newsgroups: comp.sys.palmtops
Subject: HP-95 to Unix backup procedures
Date: 15 Apr 92 13:32:16 GMT
Reply-To: edp@MATH.zko.dec.com (Eric Postpischil)
Organization: Digital Equipment Corporation

Below are files to make incremental backups of the HP-95 and to do a
full restore.


                                -- edp (Eric Postpischil)
                                "Always mount a scratch monkey."
                                edp@alien.enet.dec.com


#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  README
#	  archive
#	  backup.bat
#	  clean
#	  drive.bat
#	  restore
#	  support/awk_dir
#	  support/awk_file
#	  support/awk_mkdir
#	  support/make_restore
#	  support/parse_files
#	  support/sed_from95
#	  support/sed_mkdir
#	  support/sed_to95
#
mkdir -p support
sed 's/^X//' << 'SHAR_EOF' > README &&
XThese files support incremental backups of the HP-95's RAM "disk".  I have
Xrewritten and extended the procedure posted previously by another person.
XUnfortunately, I did not save the posting, so I cannot give proper credit.
X
XA major aspect of the rewrite allows the archive script to be invoked from
XKermit, so that it is not necessary to exit and re-invoke Kermit.  I did
Xthis because my system has a nasty habit of reverting ownership and access
Xmodes to previous settings after Kermit exits, making it impossible to
Xreacquire the terminal line without switching to superuser.  I have added
Xchecking of the directory structure -- if new directories appear on the
XHP-95, the user will be instructed to repeat the backup, at which time the
Xnew directories will be incorporated into the backup automatically.
X
X
X				-- edp (Eric Postpischil)
X				edp@being.enet.dec.com
X
X
XGetting Started
X
XYou need to make several preparations before you can use these files.
XFirst, get Kermit working.  You will need to connect your HP-95 to your
XUltrix or Unix system.  Then you should set up a file called .kermrc which
Xcontains the appropriate Kermit commands to tell it the device to which the
XHP-95 is connected, the communications characteristics, et cetera.  My
X.kermrc file contains:
X
X	set block-check 3
X	set delay 0
X	set escape-character 16
X	set file type binary
X	set line /dev/tty00
X
XAlso, you need to set the communications settings on the HP-95 and save them
Xin a configuration file (with Menu Settings Save).  Use any name for the
Xconfiguration file, but remember it; you will need it below.
X
XNext, you need to send two files in this directory to the HP-95.  The
XKermit commands to do this are:
X
X	send drive.bat C:\\_DAT\\DRIVE.BAT
X	send backup.bat C:\\_DAT\\BACKUP.BAT
X
XThe double backslashes are necessary to quote one of the backslashes;
Xotherwise Kermit uses backslashes to mean other things.  I hope your version
Xof Kermit behaves this way too, because my procedures count on it.  I have
X"C-Kermit S/W, 5A(141) 26 Apr 1990, VAX/Ultrix", according to the version
Xcommand.  If your Kermit doesn't accept double backslashes like that, this
Xbackup procedure will not work for you without modification!
X
XFinally, you need to define a char-function key (in the Char option of Setup
Xmode) on the HP-95.  This function key will go into the Filer, run the
X"drive.bat" file, go into Communications, set the communications setting,
Xand put Kermit in server mode.  I call this key "Backup" in the Comment
Xfield, and here are its Contents.  You can type this in by hand:
X
X	{FILER}{F5}c:\_dat\drive.bat{ENTER}{
X	ESC}{F4}{MENU}q{COMM}{MENU}sumath{EN
X	TER}{ESC}tkofbob3k{ESC}{ESC}{ESC}q
X
XThere is one thing in there you should change.  The first is "math", where
Xit says "sumath".  Replace "math" with the name of the configuration file
Xyou created above.  (Mine is called "math" because that is the name of the
Xworkstation I connect the HP-95 to.)  Save this char-function key definition
Xand you are ready to do backups.
X
X
XMaking a Backup
X
XTo make a backup, get into Kermit on your Ultrix or Unix system.  On the
XHP-95, press Char and the function key to which you assigned the Backup
Xsequence.  The HP-95 will go into the Filer and run drive.bat.  When that is
Xdone, you will be prompted to press any key.  Do so and the HP-95 will go into
XKermit server mode.  Then, on your Ultrix or Unix system, type the Kermit
Xcommand "take archive".  This will copy two files (files.txt and backup.bat)
Xfrom your HP-95, examine them, and then copy files that need to be backup up
Xto your system.  At the end of the backup, you will be instructed to type
X"!clean" if the backup is satisfactory.  If there were no errors during
Xthe file transfers, go ahead and do this.  If you created additional
Xdirectories on the HP-95, you will be instructed to rerun the backup.  Do
X"!clean" first and then press Char and the function key on the HP-95 again,
Xwait and press any key, and type the Kermit command "take archive".  You
Xmight have to do this several times, if you have created additional levels
Xof subdirectories.  In future backups, you will not have to repeat the
Xprocedure except when you have created new HP-95 directories.
X
XThe backup procedure will create a directory called cdrive.  This
Xcorresponds to the HP-95's directory C:\, and it will contain subdirectories
Xcorresponding to your subdirectories on the HP-95.  If you edit the file
XC:\_DAT\DRIVE.BAT on the HP-95 to add the line "dir c:\ >>a:\_dat\files.txt"
Xjust before the "backup.bat" line, then the backup procedure will backup the
Xcard you have inserted in the HP-95.  It will create a directory adrive on
Xyour system to contain the files from A:.  Note that if you do backups with
Xand without a card inserted, or with different cards inserted, the backup
Xprocedure will forget which A: files have been backed up and will back them
Xup again.
X
XThe first time you take a backup, files from ROM (C:\CHKDSK.EXE, et cetera)
Xwill be copied.  You can delete those files from the cdrive directory to
Xsave space; they will not be backed up in future invocations.
X
X
XHow to Restore Files
X
XYou can restore individual files just by deleting or renaming the files on
Xyour HP-95 and then using Kermit to send them from cdrive/wherever to
XC:\\wherever.  If your HP-95 RAM "disk" is erased, you should be able to
Xrestore all of your files by setting your HP-95 up for communications,
Xputting it in Kermit server mode, and typing "take restore" in Kermit on
Xyour Ultrix or Unix system.  This procedure will send mkdir.bat to your
XHP-95 and ask you to execute it.  Use the Filer to run mkdir.bat.  When it
Xis done, go back into Kermit server mode on the HP-95 and press return on
Xthe Ultrix or Unix system.  It will then send all the files to the HP-95.
X
XNote, I have not tried this procedure as I do not wish to erase the data on
Xmy HP-95 to try it!  It is a simple procedure, but even if you have
Xproblems, you have all the necessary data saved on your system, so you
Xshould be able to restore the files one way or another.
SHAR_EOF
chmod 0600 README || echo "restore of README fails"
sed 's/^X//' << 'SHAR_EOF' > archive &&
Xset file type text
Xget
X\_dat\files.txt
Xfiles.txt
Xget
X\_dat\backup.bat
Xbackup.bat
X!support/parse_files
Xset file type binary
Xtake kermit_commands
Xfinish
X!rm kermit_commands
SHAR_EOF
chmod 0600 archive || echo "restore of archive fails"
sed 's/^X//' << 'SHAR_EOF' > backup.bat &&
Xdir C:\_DAT	>>c:\_dat\files.txt
SHAR_EOF
chmod 0600 backup.bat || echo "restore of backup.bat fails"
sed 's/^X//' << 'SHAR_EOF' > clean &&
X#!/bin/csh
Xgrep -s KERMRECV files.txt
Xif ($status == 0) then
X	echo 'Warning, there are KERMRECV files that should be examined:'
X	grep KERMRECV files.txt
Xendif
Xmv files.txt cdrive/_dat/files.txt
Xfind . -name '*~?' -exec rm {} ";"
SHAR_EOF
chmod 0700 clean || echo "restore of clean fails"
sed 's/^X//' << 'SHAR_EOF' > drive.bat &&
Xserctl/o
Xif exist backup.new del backup.bat
Xif exist backup.new rename backup.new backup.bat
Xdir c:\ >c:\_dat\files.txt
Xbackup.bat
SHAR_EOF
chmod 0600 drive.bat || echo "restore of drive.bat fails"
sed 's/^X//' << 'SHAR_EOF' > restore &&
X!support/make_restore
Xset file type text
Xsend mkdir.bat
X!rm mkdir.bat
Xecho Please run MKDIR.BAT on the HP-95.
Xfinish
Xask \%a Press return to continue . . .
Xset file type binary
Xtake kermit_commands
Xfinish
X!rm kermit_commands
SHAR_EOF
chmod 0600 restore || echo "restore of restore fails"
sed 's/^X//' << 'SHAR_EOF' > support/awk_dir &&
X/^ Directory of  / {
X    directory=$3 
X    if (substr(directory,length(directory),1) == "\\") {
X	directory = substr(directory,1,length(directory)-1)
X    }
X}
X/^[^\.]* <DIR>  *..-..-..*/ {
X    path = directory "\\" $1
X    print "dir " path "\t>>c:\\_dat\\files.txt"
X}
SHAR_EOF
chmod 0600 support/awk_dir || echo "restore of support/awk_dir fails"
sed 's/^X//' << 'SHAR_EOF' > support/awk_file &&
X/^ Directory of  / {
X    directory=$3 
X    if (substr(directory,length(directory),1) == "\\") {
X	directory = substr(directory,1,length(directory)-1)
X    }
X}
X/^.* +[0-9]+  ..-..-..  ..:.../ {
X    if (NF==4)
X    {
X	path = directory "\\" $1 "."
X	key = $3 $4
X    }
X    else
X    {
X	path = directory "\\" $1 "." $2
X	key = $4 $5
X    }
X    if (DIFF==0) 
X	date[path] = key
X    else
X    {
X	if (date[path] != key && path != "C:\\_DAT\\FILES.TXT")
X	{
X	    print "get"
X	    print path
X	    print "Unix:" path
X	}
X    }
X}
SHAR_EOF
chmod 0600 support/awk_file || echo "restore of support/awk_file fails"
sed 's/^X//' << 'SHAR_EOF' > support/awk_mkdir &&
X/^ Directory of  / {
X    directory=$3 
X    if (substr(directory,length(directory),1) == "\\") {
X	directory = substr(directory,1,length(directory)-1)
X    }
X    print "mkdir -p Unix:" directory
X}
SHAR_EOF
chmod 0600 support/awk_mkdir || echo "restore of support/awk_mkdir fails"
sed 's/^X//' << 'SHAR_EOF' > support/make_restore &&
X#!/bin/csh
X
X# List directories to be made on C: on 95.
Xfind cdrive -type d -print | grep '/' | sed -f support/sed_mkdir >mkdir.bat
X
X# List files to be restored on C:.
Xfind cdrive ! -type d -print >kermit.from
X
X# Repeat the above for A: if a backup exists for it.
Xif (-e adrive) then
X	find adrive -type d -print | grep '/' | sed -f support/sed_mkdir \
X		>>mkdir.bat
X	find adrive ! -type d -print >>kermit.from
Xendif
X
X# Convert Unix file specifications to MS-DOS specifications.
Xsed -f support/sed_to95 kermit.from >kermit.to
X
X# Join the specifications to make Kermit SEND commands.
Xpaste kermit.from kermit.to | sed 's/^/send /' >kermit_commands
Xrm kermit.from kermit.to
SHAR_EOF
chmod 0700 support/make_restore || echo "restore of support/make_restore fails"
sed 's/^X//' << 'SHAR_EOF' > support/parse_files &&
X#!/bin/csh
X
X# Ensure previous directory listing exists, even if null.
Xif (! -e cdrive/_dat/files.txt) then
X	mkdir -p cdrive/_dat
X	touch cdrive/_dat/files.txt
Xendif
X
X# Convert new and old listings to Kermit GET commands.
Xawk -f support/awk_file cdrive/_dat/files.txt DIFF=TRUE files.txt | \
X	sed -f support/sed_from95 | tr A-Z a-z >kermit_commands
X
X# Make any new directories that appeared.
Xawk -f support/awk_mkdir files.txt | \
X	sed -f support/sed_from95 | tr A-Z a-z >mkdir_commands
Xsource mkdir_commands
Xrm mkdir_commands
X
X# Create the commands to make directory listings.
Xawk -f support/awk_dir files.txt | sort >backup.tmp
X# Compare old commands to new commands.
Xsort backup.bat | cmp -s - backup.tmp
Xif ($status != 0) then
X	# New directory listing commands are needed; send them to the 95
X	# and tell the user to redo the backup.
X	cp backup.tmp backup.new
X	cat <<EOF >>kermit_commands
Xset file type text
Xsend backup.new c:\\\\_dat\\\\backup.new
Xset file type binary
X!rm backup.new
Xecho Warning:  Directories have changed; redo backup to ensure completeness.
XEOF
Xendif
Xrm backup.bat backup.tmp
X
X# All done!
Xecho 'echo If backup is satisfactory, type "\!clean" before proceeding.' \
X	>>kermit_commands
SHAR_EOF
chmod 0700 support/parse_files || echo "restore of support/parse_files fails"
sed 's/^X//' << 'SHAR_EOF' > support/sed_from95 &&
X/Unix:/s/\\/\//g
X/Unix:/s/Unix:C:/cdrive/g
X/Unix:/s/Unix:A:/adrive/g
SHAR_EOF
chmod 0600 support/sed_from95 || echo "restore of support/sed_from95 fails"
sed 's/^X//' << 'SHAR_EOF' > support/sed_mkdir &&
Xs/^cdrive/mkdir c:/
Xs/^adrive/mkdir a:/
Xs/\//\\/g
SHAR_EOF
chmod 0600 support/sed_mkdir || echo "restore of support/sed_mkdir fails"
sed 's/^X//' << 'SHAR_EOF' > support/sed_to95 &&
Xs/^cdrive/c:/
Xs/^adrive/a:/
Xs/\//\\\\/g
SHAR_EOF
chmod 0600 support/sed_to95 || echo "restore of support/sed_to95 fails"
exit 0
Newsgroups: comp.sys.palmtops