Archiving Source Code

Need to backup that source code before you make changes? Yes! Here are two utilities that basically perform the same function of archiving your source.

The utility comes in two flavours - a UDC written by Alfredo Rego at Adager and a command-file version by Ken Robertson here at Robelle.

The Archive UDC

The archive udc copies your source code to a new account whose generated name is based on the current date. You call the udc by typing the following:
  archive filename [,groupname = "Source"]
The account created is called ARyymmdd. The source group is the default. You need to have PM capability in order to run this UDC.

The Archive Command File

The archive command file takes a slightly different tack by copying your source to a new POSIX directory, called /ar_19yymmdd_hhmm. The file will be placed relative to your home directory. You can override the relative directory by specifying your own.
For example,
  Format:
  archive filename [,groupname = "!HPCWD"]

  Example:
  archive trialmai.ktsrc /SOURCE
  A copy of trialmai.ktsrc was archived to /MISDEV/SOURCE/ar_19971204_1422/trialmai.ktsrc


Archive UDC
archive file, group="Source"
comment  option list
comment  Archives to TODAY's date, as calculated by the system
SetVar nPoint, pos (".", "!file")
if nPoint <> 0 then
  echo There is a dot in position !nPoint of the file's UNQUALIFIED name.
  echo The file's group name is the SECOND parameter, separated by a ","
  echo thus:   ":archive file, group" (the default group is "source",
  echo the default account is aryymmdd, where "yymmdd" are "today").
  Eoj
  endif
continue
SetVar ArAcct "ar"
SetVar ArAcct ArAcct + "!HpYear"
if HpMonth < 10 then
  SetVar ArAcct ArAcct + "!zero"
  endif
SetVar ArAcct ArAcct + "!HpMonth"
if HpDate < 10 then
  SetVar ArAcct ArAcct + "!zero"
  endif
SetVar ArAcct ArAcct + "!HpDate"
continue
NewAcct !ArAcct, Alfredo; pass=...
continue
NewGroup !Group.!ArAcct
copy !file.!group, !file.!group.!ArAcct; ask
echo
echo copied !file.!group to !file.!group.!ArAcct
**********

Archive Command
parm filename="?", home_dir="default"
if "!filename"="?" then
   echo
   echo Usage:  Archive filename
   echo         This command file places a copy of your the input file into an
   echo         archive directory based on today's date and time.  For example,
   echo
   echo         archive foo.src  [ homegroup=!hpcwd ]
   echo
   echo         will be copied to a new directory called
   echo
   echo         !hpcwd/ar19970511_1102/foo.src
   echo
   echo         You can specify a relative location in which to store your
   echo         archive directory.  For example,
   echo
   echo             archive foo.src /DEVL/SOURCE
   echo
   echo         The default relative location is your current working directory,
   echo         as defined from the HPCWD variable.
   echo
   return
endif
if not finfo("!filename","exists") then
   echo ***************************************************************************
   echo * Sorry, !filename does not exist.
   echo ***************************************************************************
   return
endif
comment  setup the archive directory name.  It is composed of
comment  ar_19yymmdd_hhmm
comment
comment  Once HP gets around to supporting year 2000 in a variable, then
comment  the addition of "19" should be removed.
comment
setvar archive_dir "ar_19" + "!hpyear"
if hpmonth < 10 then
    setvar archive_dir archive_dir + "0" + "!hpmonth"
else
    setvar archive_dir archive_dir + "!hpmonth"
endif
if hpday < 10 then
    setvar archive_dir archive_dir + "0" + "!hpday"
else
    setvar archive_dir archive_dir + "!hpday"
endif
setvar archive_dir archive_dir + "_"
if hphour < 10 then
    setvar archive_dir archive_dir + "0" + "!hphour"
else
    setvar archive_dir archive_dir + "!hphour"
endif
if hpminute < 10 then
    setvar archive_dir archive_dir + "0" + "!hpminute"
else
    setvar archive_dir archive_dir + "!hpminute"
endif
setjcw cierror 0
continue
if "!home_dir" = "default" then
   setvar my_home_dir hpcwd
else
   setvar my_home_dir "!home_dir"
   if rht(my_home_dir,1) = "/" then
      setvar my_home_dir lft(my_home_dir, len(my_home_dir) - 1)
   endif
endif
continue
newdir !my_home_dir/!archive_dir > errfile
setvar my_cierror cierror
if my_cierror = 906 then
   echo Warning!  The directory already exists.  Using it anyways.
   setjcw  cierror 0
else
   if my_cierror <> 0 then
      echo ***************************************************************************
      echo *         Unable to create a new directory
      echo *         !my_home_dir/!archive_dir
      echo * CIERROR = !cierror
      echo * The error message returned is:
      print errfile
      echo ***************************************************************************
      return
   endif
endif
continue
copy !filename, !my_home_dir/!archive_dir/!filename > errfile
if cierror <> 0 then
   echo ***************************************************************************
   echo *           Unable to copy the file!
   echo *  Tried: copy !filename .!archive_dir/!filename
   echo * CIERROR = !cierror
   echo * The error message returned is:
   print errfile
   echo ***************************************************************************
   return
else
   echo
   echo A copy of !filename was archived to !my_home_dir/!archive_dir/!filename
endif


....Back to the Qedit Q&A Page